2021-08-23 11:24:19 +00:00
|
|
|
<?php
|
2021-09-02 12:56:02 +00:00
|
|
|
/**
|
|
|
|
* @brief periodical, a plugin for Dotclear 2
|
2022-11-14 21:08:00 +00:00
|
|
|
*
|
2021-09-02 12:56:02 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2022-11-14 21:08:00 +00:00
|
|
|
*
|
2021-09-02 12:56:02 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2022-11-14 21:08:00 +00:00
|
|
|
*
|
2021-09-02 12:56:02 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2023-03-24 22:12:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\periodical;
|
|
|
|
|
|
|
|
use dcCore;
|
|
|
|
use dcNsProcess;
|
2023-04-22 22:14:18 +00:00
|
|
|
use Dotclear\Database\Structure;
|
2023-03-24 22:12:11 +00:00
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class Install extends dcNsProcess
|
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
|
|
|
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
|
|
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
2021-08-23 11:24:19 +00:00
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
return static::$init;
|
2022-12-03 15:30:57 +00:00
|
|
|
}
|
2021-08-23 11:24:19 +00:00
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
public static function process(): bool
|
|
|
|
{
|
2023-04-22 22:14:18 +00:00
|
|
|
if (!static::$init || is_null(dcCore::app()->blog)) {
|
2023-03-24 22:12:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-04-22 22:14:18 +00:00
|
|
|
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
2023-03-24 22:12:11 +00:00
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
// create database table
|
|
|
|
$t->__get(My::TABLE_NAME)
|
|
|
|
->field('periodical_id', 'bigint', 0, false)
|
|
|
|
->field('blog_id', 'varchar', 32, false)
|
|
|
|
->field('periodical_type', 'varchar', 32, false, "'post'")
|
|
|
|
->field('periodical_title', 'varchar', 255, false, "''")
|
|
|
|
->field('periodical_curdt', 'timestamp', 0, false, ' now()')
|
|
|
|
->field('periodical_enddt', 'timestamp', 0, false, 'now()')
|
|
|
|
->field('periodical_pub_int', 'varchar', 32, false, "'day'")
|
|
|
|
->field('periodical_pub_nb', 'smallint', 0, false, 1)
|
2021-08-23 11:24:19 +00:00
|
|
|
|
2023-03-24 22:12:11 +00:00
|
|
|
->primary('pk_periodical', 'periodical_id')
|
|
|
|
->index('idx_periodical_type', 'btree', 'periodical_type');
|
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
|
2023-03-24 22:12:11 +00:00
|
|
|
|
2023-04-22 22:14:18 +00:00
|
|
|
// set default settings
|
2023-03-24 22:12:11 +00:00
|
|
|
$s = dcCore::app()->blog->settings->get(My::id());
|
|
|
|
$s->put('periodical_active', false, 'boolean', 'Enable extension', false, true);
|
|
|
|
$s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true);
|
|
|
|
$s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true);
|
|
|
|
$s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|