2021-08-18 19:42:30 +00:00
|
|
|
<?php
|
2021-09-02 21:44:01 +00:00
|
|
|
/**
|
|
|
|
* @brief translater, a plugin for Dotclear 2
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @author Jean-Christian Denis & contributors
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-03-14 23:26:31 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\translater;
|
|
|
|
|
|
|
|
use dcCore;
|
|
|
|
use dcNamespace;
|
|
|
|
use dcNsProcess;
|
|
|
|
|
|
|
|
class Install extends dcNsProcess
|
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
2023-03-17 20:18:56 +00:00
|
|
|
if (defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
self::$init = version_compare(phpversion(), My::PHP_MIN, '>=')
|
|
|
|
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
|
|
|
}
|
2021-11-01 21:32:32 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
return self::$init;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
public static function process(): bool
|
|
|
|
{
|
|
|
|
if (!self::$init) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
self::growUp();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2022-12-22 23:15:43 +00:00
|
|
|
}
|
2021-09-24 23:58:59 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
/**
|
|
|
|
* Upgrade plugin
|
|
|
|
*
|
|
|
|
* @return bool Upgrade done
|
|
|
|
*/
|
|
|
|
public static function growUp()
|
|
|
|
{
|
|
|
|
$current = dcCore::app()->getVersion(My::id());
|
|
|
|
|
|
|
|
// use short settings id
|
|
|
|
if ($current && version_compare($current, '2022.12.22', '<')) {
|
|
|
|
$record = dcCore::app()->con->select(
|
|
|
|
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
|
|
|
"WHERE setting_ns = 'translater' "
|
|
|
|
);
|
|
|
|
while ($record->fetch()) {
|
|
|
|
if (preg_match('/^translater_(.*?)$/', $record->setting_id, $match)) {
|
|
|
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
|
|
|
$cur->setting_id = $match[1];
|
|
|
|
$cur->setting_ns = My::id();
|
|
|
|
$cur->update(
|
|
|
|
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'translater' " .
|
|
|
|
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 21:32:32 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|