pacKman/inc/Install.php

139 lines
3.6 KiB
PHP
Raw Normal View History

2021-08-16 20:48:26 +00:00
<?php
2021-09-02 20:14:32 +00:00
/**
* @brief pacKman, a plugin for Dotclear 2
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @author Jean-Christian Denis
2021-11-01 10:39:02 +00:00
*
2021-09-02 20:14:32 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2022-12-17 21:12:10 +00:00
declare(strict_types=1);
2022-12-18 23:21:11 +00:00
namespace Dotclear\Plugin\pacKman;
2021-08-16 20:48:26 +00:00
2022-12-17 21:12:10 +00:00
/* dotclear ns */
use dcCore;
2022-12-19 11:04:34 +00:00
use dcNamespace;
2021-08-16 20:48:26 +00:00
2022-12-17 21:12:10 +00:00
/* php ns */
use Exception;
2021-08-16 20:48:26 +00:00
2022-12-17 21:21:01 +00:00
class Install
2022-12-17 21:12:10 +00:00
{
2022-12-19 11:04:34 +00:00
// Module specs
2022-12-17 21:12:10 +00:00
private static $mod_conf = [
[
2022-12-19 11:04:34 +00:00
'menu_plugins',
2022-12-17 21:12:10 +00:00
'Add link to pacKman in plugins page',
false,
'boolean',
],
[
2022-12-19 11:04:34 +00:00
'pack_nocomment',
2022-12-17 21:12:10 +00:00
'Remove comments from files',
false,
'boolean',
],
[
2022-12-19 11:04:34 +00:00
'pack_overwrite',
2022-12-17 21:12:10 +00:00
'Overwrite existing package',
false,
'boolean',
],
[
2022-12-19 11:04:34 +00:00
'pack_filename',
2022-12-17 21:12:10 +00:00
'Name of package',
'%type%-%id%',
'string',
],
[
2022-12-19 11:04:34 +00:00
'secondpack_filename',
2022-12-17 21:12:10 +00:00
'Name of second package',
'%type%-%id%-%version%',
'string',
],
[
2022-12-19 11:04:34 +00:00
'pack_repository',
2022-12-17 21:12:10 +00:00
'Path to package repository',
'',
'string',
],
[
2022-12-19 11:04:34 +00:00
'pack_excludefiles',
2022-12-17 21:12:10 +00:00
'Extra files to exclude from package',
'*.zip,*.tar,*.tar.gz,.directory,.hg',
'string',
],
];
2021-08-16 20:48:26 +00:00
2022-12-19 11:04:34 +00:00
// Nothing to change below
private static $pid = '';
protected static $init = false;
2022-12-18 23:21:11 +00:00
public static function init(): bool
{
self::$pid = basename(dirname(__DIR__));
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(self::$pid, dcCore::app()->plugins->moduleInfo(self::$pid, 'version'));
2022-12-18 23:21:11 +00:00
return self::$init;
}
public static function process(): ?bool
2022-12-17 21:12:10 +00:00
{
2022-12-18 23:21:11 +00:00
if (!self::$init) {
return false;
}
2021-08-16 20:48:26 +00:00
2022-12-18 23:21:11 +00:00
try {
2022-12-19 11:04:34 +00:00
// Upgrade
self::growUp();
// Set module settings
2022-12-17 21:12:10 +00:00
foreach (self::$mod_conf as $v) {
dcCore::app()->blog->settings->__get(self::$pid)->put(
2022-12-17 21:12:10 +00:00
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
2021-08-16 20:48:26 +00:00
2022-12-17 21:12:10 +00:00
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
2021-08-16 20:48:26 +00:00
2022-12-17 21:12:10 +00:00
return false;
}
}
2022-12-19 11:04:34 +00:00
public static function growUp(): void
2022-12-19 11:04:34 +00:00
{
$current = dcCore::app()->getVersion(self::$pid);
2022-12-19 11:04:34 +00:00
// Update settings id, ns
if ($current && version_compare($current, '2022.12.19.1', '<=')) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'pacKman' "
);
while ($record->fetch()) {
if (preg_match('/^packman_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = $match[1];
$cur->setting_ns = self::$pid;
2022-12-19 11:04:34 +00:00
$cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'pacKman' " .
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
);
}
}
}
}
2021-11-06 13:56:29 +00:00
}