Files
Kleeja/install/update.php

158 lines
3.8 KiB
PHP
Raw Normal View History

2018-01-09 02:09:07 +03:00
<?php
/**
*
* @package install
2020-04-11 22:45:48 +02:00
* @copyright (c) 2007 Kleeja.net
2018-01-09 02:09:07 +03:00
* @license ./docs/license.txt
*
*/
// Report all errors, except notices
@error_reporting(E_ALL ^ E_NOTICE);
/**
* include important files
*/
define('IN_COMMON', true);
2019-05-13 00:03:24 +03:00
define('STOP_PLUGINS', true);
define('PATH', '../');
2019-05-03 23:52:08 +03:00
if (file_exists(PATH . 'config.php'))
{
2019-05-13 00:03:24 +03:00
include_once PATH . 'config.php';
2018-01-09 02:09:07 +03:00
}
2019-05-13 00:03:24 +03:00
include_once PATH . 'includes/plugins.php';
include_once PATH . 'includes/functions.php';
include_once PATH . 'includes/functions_alternative.php';
2018-01-09 02:09:07 +03:00
if (isset($dbtype) && $dbtype == 'sqlite')
{
2019-05-30 07:32:17 +03:00
include PATH . 'includes/sqlite.php';
}
else
{
2019-05-30 07:32:17 +03:00
include PATH . 'includes/mysqli.php';
}
2018-01-09 02:09:07 +03:00
include_once 'includes/functions_install.php';
2019-05-13 00:03:24 +03:00
include_once 'includes/update_schema.php';
2018-01-09 02:09:07 +03:00
2019-05-20 21:56:29 +03:00
$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname, $dbprefix);
2019-05-03 23:52:08 +03:00
2018-01-09 02:09:07 +03:00
//
2019-05-13 00:03:24 +03:00
// fix missing db_version
2018-01-09 02:09:07 +03:00
//
$config['db_version'] = inst_get_config('db_version');
2019-05-03 23:52:08 +03:00
if ($config['db_version'] == false)
{
2019-05-03 23:52:08 +03:00
$SQL->query("INSERT INTO `{$dbprefix}config` (`name` ,`value`) VALUES ('db_version', '')");
2018-01-09 02:09:07 +03:00
}
$IN_UPDATE = true;
/**
* print header
*/
if (! ip('action_file_do'))
{
2019-05-03 23:52:08 +03:00
echo gettpl('header.html');
2018-01-09 02:09:07 +03:00
}
/**
* Navigation ..
*/
switch (g('step', 'str', 'action_file'))
{
default:
case 'update_now':
2019-05-03 23:52:08 +03:00
$complete_update = true;
$update_msgs_arr = [];
$current_db_version = $config['db_version'];
2019-05-03 23:52:08 +03:00
$all_db_updates = array_keys($update_schema);
2019-05-03 23:52:08 +03:00
$available_db_updates = array_filter($all_db_updates, function ($v) use ($current_db_version) {
return $v > $current_db_version;
});
2018-01-09 02:09:07 +03:00
sort($available_db_updates);
2019-05-03 23:52:08 +03:00
if (! sizeof($available_db_updates))
{
$update_msgs_arr[] = '<span style="color:green;">' . $lang['INST_UPDATE_CUR_VER_IS_UP'] . '</span>';
$complete_update = false;
}
2018-01-09 02:09:07 +03:00
2019-05-13 00:03:24 +03:00
//
//is there any sqls
2019-05-13 00:03:24 +03:00
//
if ($complete_update)
{
//loop through available updates
foreach ($available_db_updates as $db_update_version)
{
$SQL->hideErrors();
//sqls
if (isset($update_schema[$db_update_version]['sql'])
&& sizeof($update_schema[$db_update_version]['sql']) > 0)
{
$err = '';
2019-05-03 23:52:08 +03:00
$complete_update = true;
2019-05-03 23:52:08 +03:00
foreach ($update_schema[$db_update_version]['sql'] as $name=>$sql_content)
{
$err = '';
$SQL->query($sql_content);
$err = $SQL->get_error();
2019-05-03 23:52:08 +03:00
if (strpos($err[1], 'Duplicate') !== false || $err[0] == '1062' || $err[0] == '1060')
{
$complete_update = false;
}
2019-05-03 23:52:08 +03:00
}
}
//functions
if ($complete_update)
{
if (isset($update_schema[$db_update_version]['functions']) && sizeof($update_schema[$db_update_version]['functions']) > 0)
{
foreach ($update_schema[$db_update_version]['functions'] as $n)
{
if (is_callable($n))
{
$n();
}
2019-05-03 23:52:08 +03:00
}
}
}
$sql = "UPDATE `{$dbprefix}config` SET `value` = '" . KLEEJA_DB_VERSION . "' WHERE `name` = 'db_version'";
$SQL->query($sql);
$update_msgs_arr[] = '<span style="color:green;">' . $lang['INST_UPDATE_IS_FINISH'] . '</span>';
}
2019-05-13 00:03:24 +03:00
}
2018-01-09 02:09:07 +03:00
delete_cache('', true);
echo gettpl('update_end.html');
2018-01-09 02:09:07 +03:00
break;
2018-01-09 02:09:07 +03:00
}
/**
* print footer
*/
echo gettpl('footer.html');