periodical/src/Install.php

69 lines
2.2 KiB
PHP
Raw Normal View History

2021-08-23 11:24:19 +00:00
<?php
2021-09-02 12:56:02 +00:00
/**
* @brief periodical, a plugin for Dotclear 2
*
2021-09-02 12:56:02 +00:00
* @package Dotclear
* @subpackage Plugin
*
2021-09-02 12:56:02 +00:00
* @author Jean-Christian Denis and contributors
*
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;
2023-07-29 20:48:09 +00:00
use Dotclear\Core\Process;
use Dotclear\Database\Structure;
2023-03-24 22:12:11 +00:00
use Exception;
2023-07-29 20:48:09 +00:00
class Install extends Process
2023-03-24 22:12:11 +00:00
{
public static function init(): bool
{
2023-07-29 20:48:09 +00:00
return self::status(My::checkContext(My::INSTALL));
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-07-29 20:48:09 +00:00
if (!self::status()) {
2023-03-24 22:12:11 +00:00
return false;
}
try {
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix);
2023-03-24 22:12:11 +00:00
// create database table
$t->__get(My::id())
->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');
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
2023-03-24 22:12:11 +00:00
// set default settings
2023-07-29 20:48:09 +00:00
$s = My::settings();
2023-03-24 22:12:11 +00:00
$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;
}
}
}