translater/src/Install.php

82 lines
2.2 KiB
PHP
Raw Normal View History

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;
2023-04-07 21:32:00 +00:00
use Exception;
2023-03-14 23:26:31 +00:00
class Install extends dcNsProcess
{
public static function init(): bool
{
2023-03-19 23:20:41 +00:00
static::$init = defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
2021-11-01 21:32:32 +00:00
2023-03-19 23:20:41 +00:00
return static::$init;
2021-08-18 22:48:47 +00:00
}
2023-03-14 23:26:31 +00:00
public static function process(): bool
{
2023-03-19 23:20:41 +00:00
if (!static::$init) {
2023-03-14 23:26:31 +00:00
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
}
2023-03-14 23:26:31 +00:00
/**
* Upgrade plugin
*
* @return bool Upgrade done
*/
2023-03-19 23:20:41 +00:00
private static function growUp()
2023-03-14 23:26:31 +00:00
{
$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()) {
2023-04-07 21:32:00 +00:00
if (preg_match('/^translater_(.*?)$/', $record->f('setting_id'), $match)) {
2023-04-07 21:51:19 +00:00
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
2023-04-07 21:32:00 +00:00
$cur->setField('setting_id', $match[1]);
$cur->setField('setting_ns', My::id());
2023-03-14 23:26:31 +00:00
$cur->update(
2023-04-07 21:32:00 +00:00
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'translater' " .
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->f('blog_id')) . "' "))
2023-03-14 23:26:31 +00:00
);
}
}
2021-11-01 21:32:32 +00:00
2023-03-14 23:26:31 +00:00
return true;
}
return false;
}
}