89 lines
2.7 KiB
PHP
89 lines
2.7 KiB
PHP
<?php
|
|
|
|
require_once 'core/settings.php';
|
|
|
|
class Installer
|
|
{
|
|
protected $db;
|
|
protected $installPath;
|
|
public $_registry;
|
|
|
|
public function __construct(Settings $_registry)
|
|
{
|
|
$this->_registry = $_registry;
|
|
}
|
|
|
|
public function setUp($db, $installPath)
|
|
{
|
|
$this->db = $db;
|
|
$this->installPath = $installPath;
|
|
}
|
|
|
|
function getSetupFile($name)
|
|
{
|
|
return Path::join(call_user_func($this->installPath, $name), "setup.php");
|
|
}
|
|
|
|
// Ïðîâåðêà âåðñèè îáíîâëåíèÿ
|
|
function isChanged($name) // Èíôîðìàöèÿ î ìîäóëÿõ
|
|
{
|
|
$item = $this->_registry->readKey(array($name));
|
|
if ($item) {
|
|
$setup = $this->getSetupFile($name);
|
|
if (file_exists($setup) && (filemtime($setup) > $item['time'])) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function installSQL(array $sql, $version_new, $version_old, $name)
|
|
{
|
|
require_once "core/setup.php";
|
|
foreach ($sql as $version => $install) {
|
|
if (version_compare($version, $version_new, "<=") && version_compare($version, $version_old, ">")) {
|
|
// this->installPath this->db
|
|
$file = Path::join(call_user_func($this->installPath, $name), "sql", $install);
|
|
Setup::batchSQL($this->db, $file);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Óñòàíàâëèâàåò îáíîâëåíèÿ åñëè åñòü
|
|
function doUpdates($name, $force = false) // Óñòàíîâêà ìîäóëÿ
|
|
{
|
|
$setup = $this->getSetupFile($name);
|
|
if (file_exists($setup) && ($this->isChanged($name) || $force)) {
|
|
|
|
$registry = $this->_registry;
|
|
$settings = new Settings($setup);
|
|
$settings->read();
|
|
|
|
$item = $registry->readKey(array($name));
|
|
|
|
$version_new = $settings->get('version');
|
|
if ($item) {
|
|
$version_old = $item['version'];
|
|
} else {
|
|
$version_old = "0.0";
|
|
$registry->writeKey(array($name), array());
|
|
}
|
|
|
|
if (version_compare($version_old, $settings->get('version'), "!=")) {
|
|
$sql = $settings->get('sql');
|
|
if (is_array($sql)) {
|
|
$this->installSQL($sql, $version_new, $version_old, $name);
|
|
}
|
|
}
|
|
|
|
// Îáíîâëåíèå âåðñèè ìåíþ
|
|
$registry->writeKey(array($name), $settings->get('settings'));
|
|
$registry->writeKey(array($name),
|
|
array('version' => $version_new,
|
|
'time' => filemtime($setup)));
|
|
$registry->write();
|
|
}
|
|
}
|
|
}
|
|
|