2021-09-02 22:04:20 +00:00
|
|
|
<?php
|
2021-09-02 22:18:08 +00:00
|
|
|
/**
|
|
|
|
* @brief activityReport, a plugin for Dotclear 2
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-02 22:18:08 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-02 22:18:08 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-02 22:18:08 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-04-20 12:22:43 +00:00
|
|
|
declare(strict_types=1);
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
namespace Dotclear\Plugin\activityReport;
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2023-04-20 12:22:43 +00:00
|
|
|
use dcCore;
|
|
|
|
use dcNsProcess;
|
2023-04-23 08:31:49 +00:00
|
|
|
use Dotclear\Database\Structure;
|
2023-04-20 12:22:43 +00:00
|
|
|
use Dotclear\Database\Statement\{
|
|
|
|
DropStatement,
|
|
|
|
TruncateStatement
|
|
|
|
};
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install process.
|
|
|
|
*/
|
|
|
|
class Install extends dcNsProcess
|
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
|
|
|
static::$init = defined('DC_CONTEXT_ADMIN')
|
2023-05-11 22:37:45 +00:00
|
|
|
&& is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version'))
|
2023-04-20 12:22:43 +00:00
|
|
|
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
|
|
|
|
|
|
|
return static::$init;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function process(): bool
|
|
|
|
{
|
|
|
|
if (!static::$init) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
self::beforeGrowUp();
|
2022-11-18 20:24:30 +00:00
|
|
|
|
2023-04-23 08:31:49 +00:00
|
|
|
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
|
|
|
$s->__get(My::ACTIVITY_TABLE_NAME)
|
|
|
|
->field('activity_id', 'bigint', 0, false)
|
|
|
|
->field('activity_type', 'varchar', 32, false, "'" . My::id() . "'")
|
|
|
|
->field('blog_id', 'varchar', 32, true)
|
|
|
|
->field('activity_group', 'varchar', 32, false)
|
|
|
|
->field('activity_action', 'varchar', 32, false)
|
|
|
|
->field('activity_logs', 'text', 0, false)
|
|
|
|
->field('activity_dt', 'timestamp', 0, false, 'now()')
|
|
|
|
->field('activity_status', 'smallint', 0, false, 0)
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
->primary('pk_activity', 'activity_id')
|
|
|
|
->index('idx_activity_type', 'btree', 'activity_type')
|
|
|
|
->index('idx_activity_blog_id', 'btree', 'blog_id')
|
|
|
|
->index('idx_activity_action', 'btree', 'activity_group', 'activity_action')
|
|
|
|
->index('idx_activity_status', 'btree', 'activity_status');
|
|
|
|
|
2023-04-23 08:31:49 +00:00
|
|
|
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do some action on previous version before install.
|
|
|
|
*/
|
|
|
|
private static function beforeGrowUp(): void
|
|
|
|
{
|
|
|
|
// sorry not sorry we restart from scratch
|
2023-05-11 22:37:45 +00:00
|
|
|
if (is_string(dcCore::app()->getVersion('activityReport'))
|
|
|
|
&& version_compare(dcCore::app()->getVersion('activityReport'), '3.0', '<')
|
|
|
|
) {
|
2023-04-23 08:31:49 +00:00
|
|
|
$struct = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
2023-04-20 12:22:43 +00:00
|
|
|
|
|
|
|
if ($struct->tableExists('activity')) {
|
|
|
|
(new TruncateStatement())->from(dcCore::app()->prefix . 'activity')->truncate();
|
|
|
|
}
|
|
|
|
if ($struct->tableExists('activity_settings')) {
|
|
|
|
(new TruncateStatement())->from(dcCore::app()->prefix . 'activity_settings')->truncate();
|
|
|
|
(new DropStatement())->from(dcCore::app()->prefix . 'activity_settings')->drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|