Current oav website
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
/**
|
||||
@brief Simple descriptor for tabs, groups and more
|
||||
|
||||
At this time this class is used in same way an arrayObject
|
||||
but in futur it could be completed with advance methods.
|
||||
*/
|
||||
class dcMaintenanceDescriptor
|
||||
{
|
||||
protected $id;
|
||||
protected $name;
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Constructor (really ?!).
|
||||
*
|
||||
* @param id <b>string<b> Tab ID
|
||||
* @param name <b>string<b> Tab name
|
||||
* @param options <b>string<b> Options
|
||||
*/
|
||||
public function __construct($id, $name, $options = [])
|
||||
{
|
||||
$this->id = (string) $id;
|
||||
$this->name = (string) $name;
|
||||
$this->options = (array) $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID.
|
||||
*
|
||||
* @return <b>string</b> ID
|
||||
*/
|
||||
public function id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return <b>string</b> Name
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option.
|
||||
*
|
||||
* Option called "summary" and "description" are used.
|
||||
*
|
||||
* @param key <b>string<b> Option key
|
||||
* @return <b>string</b> Option value
|
||||
*/
|
||||
public function option($key)
|
||||
{
|
||||
return isset($this->options[$key]) ? $this->options[$key] : null;
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->option($key);
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
public function __isset($key)
|
||||
{
|
||||
return isset($this->options[$key]);
|
||||
}
|
||||
}
|
||||
281
dotclear._no/plugins/maintenance/inc/class.dc.maintenance.php
Normal file
281
dotclear._no/plugins/maintenance/inc/class.dc.maintenance.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
/**
|
||||
Main class to call everything related to maintenance.
|
||||
*/
|
||||
class dcMaintenance
|
||||
{
|
||||
public $core;
|
||||
public $p_url;
|
||||
|
||||
private $tasks = [];
|
||||
private $tabs = [];
|
||||
private $groups = [];
|
||||
private $logs = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param core <b>dcCore</b> dcCore instance
|
||||
*/
|
||||
public function __construct($core)
|
||||
{
|
||||
$this->core = $core;
|
||||
$this->p_url = $core->adminurl->get('admin.plugin.maintenance');
|
||||
$logs = $this->getLogs();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize list of tabs and groups and tasks.
|
||||
*
|
||||
* To register a tab or group or task,
|
||||
* use behavior dcMaintenanceInit then a method of
|
||||
* dcMaintenance like addTab('myTab', ...).
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
# --BEHAVIOR-- dcMaintenanceInit
|
||||
$this->core->callBehavior('dcMaintenanceInit', $this);
|
||||
}
|
||||
|
||||
/// @name Tab methods
|
||||
//@{
|
||||
/**
|
||||
* Add a tab.
|
||||
*
|
||||
* @param id <b>string<b> Tab ID
|
||||
* @param name <b>string<b> Tab name
|
||||
* @param options <b>string<b> Options
|
||||
* @return <b>dcMaintenance</b> Self
|
||||
*/
|
||||
public function addTab($id, $name, $options = [])
|
||||
{
|
||||
$this->tabs[$id] = new dcMaintenanceDescriptor($id, $name, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tab.
|
||||
*
|
||||
* @param id <b>string</b> Tab ID
|
||||
* @return <b>object</b> dcMaintenanceDescriptor of a tab
|
||||
*/
|
||||
public function getTab($id)
|
||||
{
|
||||
return array_key_exists($id, $this->tabs) ? $this->tabs[$id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tabs.
|
||||
*
|
||||
* @return <b>array</b> Array of tabs ID and name
|
||||
*/
|
||||
public function getTabs()
|
||||
{
|
||||
return $this->tabs;
|
||||
}
|
||||
//@}
|
||||
|
||||
/// @name Group methods
|
||||
//@{
|
||||
/**
|
||||
* Add a group.
|
||||
*
|
||||
* @param id <b>string<b> Group ID
|
||||
* @param name <b>string<b> Group name
|
||||
* @param options <b>string<b> Options
|
||||
* @return <b>dcMaintenance</b> Self
|
||||
*/
|
||||
public function addGroup($id, $name, $options = [])
|
||||
{
|
||||
$this->groups[$id] = new dcMaintenanceDescriptor($id, $name, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a group.
|
||||
*
|
||||
* @param id <b>string</b> Group ID
|
||||
* @return <b>object</b> dcMaintenanceDescriptor of a group
|
||||
*/
|
||||
public function getGroup($id)
|
||||
{
|
||||
return array_key_exists($id, $this->groups) ? $this->groups[$id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups.
|
||||
*
|
||||
* @return <b>array</b> Array of groups ID and descriptor
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->groups;
|
||||
}
|
||||
//@}
|
||||
|
||||
/// @name Task methods
|
||||
//@{
|
||||
/**
|
||||
* Add a task.
|
||||
*
|
||||
* @param task <b>mixed<b> Class name or object
|
||||
* @return <b>boolean</b> True if it is added
|
||||
* @return <b>dcMaintenance</b> Self
|
||||
*/
|
||||
public function addTask($task)
|
||||
{
|
||||
if (class_exists($task) && is_subclass_of($task, 'dcMaintenanceTask')) {
|
||||
$this->tasks[$task] = new $task($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a task object.
|
||||
*
|
||||
* @param id <b>string</b> task ID
|
||||
* @return <b>mixed</b> Task object or null if not exists
|
||||
*/
|
||||
public function getTask($id)
|
||||
{
|
||||
return array_key_exists($id, $this->tasks) ? $this->tasks[$id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks.
|
||||
*
|
||||
* @return <b>array</b> Array of tasks objects
|
||||
*/
|
||||
public function getTasks()
|
||||
{
|
||||
return $this->tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers for plugin maintenance admin page.
|
||||
*
|
||||
* @return <b>string</b> Page headers
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
$res = '';
|
||||
foreach ($this->tasks as $task) {
|
||||
$res .= $task->header();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
//@}
|
||||
|
||||
/// @name Log methods
|
||||
//@{
|
||||
/**
|
||||
* Set log for a task.
|
||||
*
|
||||
* @param id <b>string</b> Task ID
|
||||
*/
|
||||
public function setLog($id)
|
||||
{
|
||||
// Check if taks exists
|
||||
if (!$this->getTask($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get logs from this task
|
||||
$rs = $this->core->con->select(
|
||||
'SELECT log_id ' .
|
||||
'FROM ' . $this->core->prefix . 'log ' .
|
||||
"WHERE log_msg = '" . $this->core->con->escape($id) . "' " .
|
||||
"AND log_table = 'maintenance' "
|
||||
);
|
||||
|
||||
$logs = [];
|
||||
while ($rs->fetch()) {
|
||||
$logs[] = $rs->log_id;
|
||||
}
|
||||
|
||||
// Delete old logs
|
||||
if (!empty($logs)) {
|
||||
$this->core->log->delLogs($logs);
|
||||
}
|
||||
|
||||
// Add new log
|
||||
$cur = $this->core->con->openCursor($this->core->prefix . 'log');
|
||||
|
||||
$cur->log_msg = $id;
|
||||
$cur->log_table = 'maintenance';
|
||||
$cur->user_id = $this->core->auth->userID();
|
||||
|
||||
$this->core->log->addLog($cur);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all maintenance logs.
|
||||
*/
|
||||
public function delLogs()
|
||||
{
|
||||
// Retrieve logs from this task
|
||||
$rs = $this->core->log->getLogs([
|
||||
'log_table' => 'maintenance',
|
||||
'blog_id' => 'all'
|
||||
]);
|
||||
|
||||
$logs = [];
|
||||
while ($rs->fetch()) {
|
||||
$logs[] = $rs->log_id;
|
||||
}
|
||||
|
||||
// Delete old logs
|
||||
if (!empty($logs)) {
|
||||
$this->core->log->delLogs($logs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logs
|
||||
*
|
||||
* Return [
|
||||
* task id => [
|
||||
* timestamp of last execution,
|
||||
* logged on current blog or not
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
* @return <b>array</b> List of logged tasks
|
||||
*/
|
||||
public function getLogs()
|
||||
{
|
||||
if ($this->logs === null) {
|
||||
$rs = $this->core->log->getLogs([
|
||||
'log_table' => 'maintenance',
|
||||
'blog_id' => 'all'
|
||||
]);
|
||||
|
||||
$this->logs = [];
|
||||
while ($rs->fetch()) {
|
||||
$this->logs[$rs->log_msg] = [
|
||||
'ts' => strtotime($rs->log_dt),
|
||||
'blog' => $rs->blog_id == $this->core->blog->id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->logs;
|
||||
}
|
||||
//@}
|
||||
}
|
||||
@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
/**
|
||||
@brief Maintenance plugin task class.
|
||||
|
||||
Every task of maintenance must extend this class.
|
||||
*/
|
||||
class dcMaintenanceTask
|
||||
{
|
||||
protected $maintenance;
|
||||
protected $core;
|
||||
protected $p_url;
|
||||
protected $code;
|
||||
protected $ts = 0;
|
||||
protected $expired = 0;
|
||||
protected $ajax = false;
|
||||
protected $blog = false;
|
||||
protected $perm = null;
|
||||
|
||||
protected $id;
|
||||
protected $name;
|
||||
protected $description;
|
||||
protected $tab = 'maintenance';
|
||||
protected $group = 'other';
|
||||
|
||||
protected $task;
|
||||
protected $step;
|
||||
protected $error;
|
||||
protected $success;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* If your task required something on construct,
|
||||
* use method init() to do it.
|
||||
*
|
||||
* @param maintenance <b>dcMaintenance</b> dcMaintenance instance
|
||||
* @param p_url <b>string</b> Maintenance plugin url
|
||||
*/
|
||||
public function __construct($maintenance)
|
||||
{
|
||||
$this->maintenance = $maintenance;
|
||||
$this->core = $maintenance->core;
|
||||
$this->init();
|
||||
$this->id = null;
|
||||
|
||||
if ($this->perm() === null && !$this->core->auth->isSuperAdmin()
|
||||
|| !$this->core->auth->check($this->perm(), $this->core->blog->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->p_url = $maintenance->p_url;
|
||||
$this->id = get_class($this);
|
||||
|
||||
if (!$this->name) {
|
||||
$this->name = get_class($this);
|
||||
}
|
||||
if (!$this->error) {
|
||||
$this->error = __('Failed to execute task.');
|
||||
}
|
||||
if (!$this->success) {
|
||||
$this->success = __('Task successfully executed.');
|
||||
}
|
||||
|
||||
$this->core->blog->settings->addNamespace('maintenance');
|
||||
$ts = $this->core->blog->settings->maintenance->get('ts_' . $this->id);
|
||||
|
||||
$this->ts = abs((integer) $ts);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize task object.
|
||||
*
|
||||
* Better to set translated messages here than
|
||||
* to rewrite constructor.
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task permission.
|
||||
*
|
||||
* Return user permission required to run this task
|
||||
* or null for super admin.
|
||||
*
|
||||
* @return <b>mixed</b> Permission.
|
||||
*/
|
||||
public function perm()
|
||||
{
|
||||
return $this->perm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task scope.
|
||||
*.
|
||||
* Is task limited to current blog.
|
||||
*
|
||||
* @return <b>boolean</b> Limit to blog
|
||||
*/
|
||||
public function blog()
|
||||
{
|
||||
return $this->blog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $code for task having multiple steps.
|
||||
*
|
||||
* @param code <b>integer</b> Code used for task execution
|
||||
*/
|
||||
public function code($code)
|
||||
{
|
||||
$this->code = (integer) $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp between maintenances.
|
||||
*
|
||||
* @return <b>intetger</b> Timestamp
|
||||
*/
|
||||
public function ts()
|
||||
{
|
||||
return $this->ts === false ? false : abs((integer) $this->ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task expired.
|
||||
*
|
||||
* This return:
|
||||
* - Timstamp of last update if it expired
|
||||
* - False if it not expired or has no recall time
|
||||
* - Null if it has never been executed
|
||||
*
|
||||
* @return <b>mixed</b> Last update
|
||||
*/
|
||||
public function expired()
|
||||
{
|
||||
if ($this->expired === 0) {
|
||||
if (!$this->ts()) {
|
||||
$this->expired = false;
|
||||
} else {
|
||||
$this->expired = null;
|
||||
$logs = [];
|
||||
foreach ($this->maintenance->getLogs() as $id => $log) {
|
||||
if ($id != $this->id() || $this->blog && !$log['blog']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->expired = $log['ts'] + $this->ts() < time() ? $log['ts'] : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->expired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task ID.
|
||||
*
|
||||
* @return <b>string</b> Task ID (class name)
|
||||
*/
|
||||
public function id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task name.
|
||||
*
|
||||
* @return <b>string</b> Task name
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task description.
|
||||
*
|
||||
* @return <b>string</b> Description
|
||||
*/
|
||||
public function description()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task tab.
|
||||
*
|
||||
* @return <b>mixed</b> Task tab ID or null
|
||||
*/
|
||||
public function tab()
|
||||
{
|
||||
return $this->tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task group.
|
||||
*
|
||||
* If task required a full tab,
|
||||
* this must be returned null.
|
||||
*
|
||||
* @return <b>mixed</b> Task group ID or null
|
||||
*/
|
||||
public function group()
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use ajax
|
||||
*
|
||||
* Is task use maintenance ajax script
|
||||
* for steps process.
|
||||
*
|
||||
* @return <b>boolean</b> Use ajax
|
||||
*/
|
||||
public function ajax()
|
||||
{
|
||||
return (boolean) $this->ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task message.
|
||||
*
|
||||
* This message is used on form button.
|
||||
*
|
||||
* @return <b>string</b> Message
|
||||
*/
|
||||
public function task()
|
||||
{
|
||||
return $this->task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get step message.
|
||||
*
|
||||
* This message is displayed during task step execution.
|
||||
*
|
||||
* @return <b>mixed</b> Message or null
|
||||
*/
|
||||
public function step()
|
||||
{
|
||||
return $this->step;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get success message.
|
||||
*
|
||||
* This message is displayed when task is accomplished.
|
||||
*
|
||||
* @return <b>mixed</b> Message or null
|
||||
*/
|
||||
public function success()
|
||||
{
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error message.
|
||||
*
|
||||
* This message is displayed on error.
|
||||
*
|
||||
* @return <b>mixed</b> Message or null
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get header.
|
||||
*
|
||||
* Headers required on maintenance page.
|
||||
*
|
||||
* @return <b>mixed</b> Message or null
|
||||
*/
|
||||
public function header()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content.
|
||||
*
|
||||
* Content for full tab task.
|
||||
*
|
||||
* @return <b>string</b> Tab's content
|
||||
*/
|
||||
public function content()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute task.
|
||||
*
|
||||
* @return <b>mixed</b> :
|
||||
* - FALSE on error,
|
||||
* - TRUE if task is finished
|
||||
* - INTEGER if task required a next step
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log task execution.
|
||||
*
|
||||
* Sometimes we need to log task execution
|
||||
* direct from task itself.
|
||||
*
|
||||
*/
|
||||
protected function log()
|
||||
{
|
||||
$this->maintenance->setLog($this->id);
|
||||
}
|
||||
|
||||
public function help()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceCache extends dcMaintenanceTask
|
||||
{
|
||||
protected $group = 'purge';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Empty templates cache directory');
|
||||
$this->success = __('Templates cache directory emptied.');
|
||||
$this->error = __('Failed to empty templates cache directory.');
|
||||
|
||||
$this->description = __("It may be useful to empty this cache when modifying a theme's .html or .css files (or when updating a theme or plugin). Notice : with some hosters, the templates cache cannot be emptied with this plugin. You may then have to delete the directory <strong>/cbtpl/</strong> directly on the server with your FTP software.");
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->core->emptyTemplatesCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceCountcomments extends dcMaintenanceTask
|
||||
{
|
||||
protected $group = 'index';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Count again comments and trackbacks');
|
||||
$this->success = __('Comments and trackback counted.');
|
||||
$this->error = __('Failed to count comments and trackbacks.');
|
||||
|
||||
$this->description = __('Count again comments and trackbacks allows to check their exact numbers. This operation can be useful when importing from another blog platform (or when migrating from dotclear 1 to dotclear 2).');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->core->countAllComments();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceCSP extends dcMaintenanceTask
|
||||
{
|
||||
protected $group = 'purge';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Delete the Content-Security-Policy report file');
|
||||
$this->success = __('Content-Security-Policy report file has been deleted.');
|
||||
$this->error = __('Failed to delete the Content-Security-Policy report file.');
|
||||
|
||||
$this->description = __("Remove the Content-Security-Policy report file.");
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$csp_file = path::real(DC_VAR) . '/csp/csp_report.json';
|
||||
if (file_exists($csp_file)) {
|
||||
unlink($csp_file);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceIndexcomments extends dcMaintenanceTask
|
||||
{
|
||||
protected $ajax = true;
|
||||
protected $group = 'index';
|
||||
protected $limit = 500;
|
||||
protected $step_task;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->name = __('Search engine index');
|
||||
$this->task = __('Index all comments for search engine');
|
||||
$this->step_task = __('Next');
|
||||
$this->step = __('Indexing comment %d to %d.');
|
||||
$this->success = __('Comments index done.');
|
||||
$this->error = __('Failed to index comments.');
|
||||
|
||||
$this->description = __('Index all comments and trackbacks in search engine index. This operation is necessary, after importing content in your blog, to use internal search engine, on public and private pages.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->code = $this->core->indexAllComments($this->code, $this->limit);
|
||||
|
||||
return $this->code ?: true;
|
||||
}
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->code ? $this->step_task : $this->task;
|
||||
}
|
||||
|
||||
public function step()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : null;
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : $this->success;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceIndexposts extends dcMaintenanceTask
|
||||
{
|
||||
protected $ajax = true;
|
||||
protected $group = 'index';
|
||||
protected $limit = 500;
|
||||
protected $step_task;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->name = __('Search engine index');
|
||||
$this->task = __('Index all entries for search engine');
|
||||
$this->step_task = __('Next');
|
||||
$this->step = __('Indexing entry %d to %d.');
|
||||
$this->success = __('Entries index done.');
|
||||
$this->error = __('Failed to index entries.');
|
||||
|
||||
$this->description = __('Index all entries in search engine index. This operation is necessary, after importing content in your blog, to use internal search engine, on public and private pages.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->code = $this->core->indexAllPosts($this->code, $this->limit);
|
||||
|
||||
return $this->code ?: true;
|
||||
}
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->code ? $this->step_task : $this->task;
|
||||
}
|
||||
|
||||
public function step()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : null;
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : $this->success;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceLogs extends dcMaintenanceTask
|
||||
{
|
||||
public static $keep_maintenance_logs = true;
|
||||
|
||||
protected $group = 'purge';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Delete all logs');
|
||||
$this->success = __('Logs deleted.');
|
||||
$this->error = __('Failed to delete logs.');
|
||||
|
||||
$this->description = __('Logs record all activity and connection to your blog history. Unless you need to keep this history, consider deleting these logs from time to time.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
if (dcMaintenanceLogs::$keep_maintenance_logs) {
|
||||
$this->core->con->execute(
|
||||
'DELETE FROM ' . $this->core->prefix . 'log ' .
|
||||
"WHERE log_table <> 'maintenance' "
|
||||
);
|
||||
} else {
|
||||
$this->core->log->delLogs(null, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceSynchpostsmeta extends dcMaintenanceTask
|
||||
{
|
||||
protected $ajax = true;
|
||||
protected $group = 'index';
|
||||
protected $limit = 100;
|
||||
protected $step_task;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->name = __('Entries metadata');
|
||||
$this->task = __('Synchronize entries metadata');
|
||||
$this->step_task = __('Next');
|
||||
$this->step = __('Synchronize entry %d to %d.');
|
||||
$this->success = __('Entries metadata synchronize done.');
|
||||
$this->error = __('Failed to synchronize entries metadata.');
|
||||
|
||||
$this->description = __('Synchronize all entries metadata could be useful after importing content in your blog or do bad operation on database tables.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->code = $this->synchronizeAllPostsmeta($this->code, $this->limit);
|
||||
|
||||
return $this->code ?: true;
|
||||
}
|
||||
|
||||
public function task()
|
||||
{
|
||||
return $this->code ? $this->step_task : $this->task;
|
||||
}
|
||||
|
||||
public function step()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : null;
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
return $this->code ? sprintf($this->step, $this->code - $this->limit, $this->code) : $this->success;
|
||||
}
|
||||
|
||||
protected function synchronizeAllPostsmeta($start = null, $limit = null)
|
||||
{
|
||||
// Get number of posts
|
||||
$rs = $this->core->con->select('SELECT COUNT(post_id) FROM ' . $this->core->prefix . 'post');
|
||||
$count = $rs->f(0);
|
||||
|
||||
// Get posts ids to update
|
||||
$req_limit = $start !== null && $limit !== null ? $this->core->con->limit($start, $limit) : '';
|
||||
$rs = $this->core->con->select('SELECT post_id FROM ' . $this->core->prefix . 'post ' . $req_limit, true);
|
||||
|
||||
// Update posts meta
|
||||
while ($rs->fetch()) {
|
||||
$rs_meta = $this->core->con->select('SELECT meta_id, meta_type FROM ' . $this->core->prefix . 'meta WHERE post_id = ' . $rs->post_id . ' ');
|
||||
|
||||
$meta = array();
|
||||
while ($rs_meta->fetch()) {
|
||||
$meta[$rs_meta->meta_type][] = $rs_meta->meta_id;
|
||||
}
|
||||
|
||||
$cur = $this->core->con->openCursor($this->core->prefix . 'post');
|
||||
$cur->post_meta = serialize($meta);
|
||||
$cur->update('WHERE post_id = ' . $rs->post_id);
|
||||
}
|
||||
$this->core->blog->triggerBlog();
|
||||
|
||||
// Return next step
|
||||
return $start + $limit > $count ? null : $start + $limit;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceVacuum extends dcMaintenanceTask
|
||||
{
|
||||
protected $group = 'optimize';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->name = __('Optimise database');
|
||||
$this->task = __('optimize tables');
|
||||
$this->success = __('Optimization successful.');
|
||||
$this->error = __('Failed to optimize tables.');
|
||||
|
||||
$this->description = __("After numerous delete or update operations on Dotclear's database, it gets fragmented. Optimizing will allow to defragment it. It has no incidence on your data's integrity. It is recommended to optimize before any blog export.");
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$schema = dbSchema::init($this->core->con);
|
||||
|
||||
foreach ($schema->getTables() as $table) {
|
||||
if (strpos($table, $this->core->prefix) === 0) {
|
||||
$this->core->con->vacuum($table);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceZipmedia extends dcMaintenanceTask
|
||||
{
|
||||
protected $perm = 'admin';
|
||||
protected $blog = true;
|
||||
protected $tab = 'backup';
|
||||
protected $group = 'zipblog';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Download media folder of current blog');
|
||||
|
||||
$this->description = __('It may be useful to backup your media folder. This compress all content of media folder into a single zip file. Notice : with some hosters, the media folder cannot be compressed with this plugin if it is too big.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
// Instance media
|
||||
$this->core->media = new dcMedia($this->core);
|
||||
$this->core->media->chdir(null);
|
||||
$this->core->media->getDir();
|
||||
|
||||
// Create zip
|
||||
@set_time_limit(300);
|
||||
$fp = fopen('php://output', 'wb');
|
||||
$zip = new fileZip($fp);
|
||||
$zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
|
||||
$zip->addDirectory($this->core->media->root . '/', '', true);
|
||||
|
||||
// Log task execution here as we sent file and stop script
|
||||
$this->log();
|
||||
|
||||
// Send zip
|
||||
header('Content-Disposition: attachment;filename=' . date('Y-m-d') . '-' . $this->core->blog->id . '-' . 'media.zip');
|
||||
header('Content-Type: application/x-zip');
|
||||
$zip->write();
|
||||
unset($zip);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief maintenance, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugins
|
||||
*
|
||||
* @copyright Olivier Meunier & Association Dotclear
|
||||
* @copyright GPL-2.0-only
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {return;}
|
||||
|
||||
class dcMaintenanceZiptheme extends dcMaintenanceTask
|
||||
{
|
||||
protected $perm = 'admin';
|
||||
protected $blog = true;
|
||||
protected $tab = 'backup';
|
||||
protected $group = 'zipblog';
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->task = __('Download active theme of current blog');
|
||||
|
||||
$this->description = __('It may be useful to backup the active theme before any change or update. This compress theme folder into a single zip file.');
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
// Get theme path
|
||||
$path = $this->core->blog->themes_path;
|
||||
$theme = $this->core->blog->settings->system->theme;
|
||||
$dir = path::real($path . '/' . $theme);
|
||||
if (empty($path) || empty($theme) || !is_dir($dir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create zip
|
||||
@set_time_limit(300);
|
||||
$fp = fopen('php://output', 'wb');
|
||||
$zip = new fileZip($fp);
|
||||
$zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
|
||||
$zip->addDirectory($dir . '/', '', true);
|
||||
|
||||
// Log task execution here as we sent file and stop script
|
||||
$this->log();
|
||||
|
||||
// Send zip
|
||||
header('Content-Disposition: attachment;filename=theme-' . $theme . '.zip');
|
||||
header('Content-Type: application/x-zip');
|
||||
$zip->write();
|
||||
unset($zip);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user