2021-08-18 19:42:30 +00:00
|
|
|
<?php
|
2023-10-21 09:45:02 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\translater;
|
|
|
|
|
2023-10-21 09:45:02 +00:00
|
|
|
use Dotclear\App;
|
2023-07-29 12:54:35 +00:00
|
|
|
use Dotclear\Core\Process;
|
2023-10-21 09:45:02 +00:00
|
|
|
use Dotclear\Database\Statement\SelectStatement;
|
2023-04-07 21:32:00 +00:00
|
|
|
use Exception;
|
2023-03-14 23:26:31 +00:00
|
|
|
|
2023-10-21 09:45:02 +00:00
|
|
|
/**
|
|
|
|
* @brief translater install class.
|
|
|
|
* @ingroup translater
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-07-29 12:54:35 +00:00
|
|
|
class Install extends Process
|
2023-03-14 23:26:31 +00:00
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
2023-07-29 12:54:35 +00:00
|
|
|
return self::status(My::checkContext(My::INSTALL));
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
public static function process(): bool
|
|
|
|
{
|
2023-07-29 12:54:35 +00:00
|
|
|
if (!self::status()) {
|
2023-03-14 23:26:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
self::growUp();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
2023-10-21 09:45:02 +00:00
|
|
|
App::error()->add($e->getMessage());
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2023-03-19 23:20:41 +00:00
|
|
|
private static function growUp()
|
2023-03-14 23:26:31 +00:00
|
|
|
{
|
2023-10-21 09:45:02 +00:00
|
|
|
$current = App::version()->getVersion(My::id());
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
// use short settings id
|
|
|
|
if ($current && version_compare($current, '2022.12.22', '<')) {
|
2023-10-21 09:45:02 +00:00
|
|
|
$sql = new SelectStatement();
|
|
|
|
$record = $sql
|
|
|
|
->column('*')
|
|
|
|
->from(App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME)
|
|
|
|
->where("setting_ns = 'translater' ")
|
|
|
|
->select();
|
|
|
|
|
|
|
|
if (!$record) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
while ($record->fetch()) {
|
2023-04-07 21:32:00 +00:00
|
|
|
if (preg_match('/^translater_(.*?)$/', $record->f('setting_id'), $match)) {
|
2023-10-21 09:45:02 +00:00
|
|
|
$cur = App::blogWorkspace()->openBlogWorkspaceCursor();
|
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' " .
|
2023-10-21 09:45:02 +00:00
|
|
|
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . 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;
|
|
|
|
}
|
|
|
|
}
|