Переделка для composer autoload
This commit is contained in:
parent
ad69746347
commit
b5641db607
100 changed files with 14 additions and 325 deletions
87
src/controller/installer.php
Normal file
87
src/controller/installer.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
class Controller_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue