postWidgetText/_install.php

86 lines
2.5 KiB
PHP
Raw Normal View History

2021-09-10 19:06:49 +00:00
<?php
2021-09-10 19:18:51 +00:00
/**
* @brief postWidgetText, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-10 19:06:49 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
2021-09-10 19:18:51 +00:00
return null;
2021-09-10 19:06:49 +00:00
}
try {
2021-09-10 19:18:51 +00:00
# Check module version
if (version_compare(
$core->getVersion('postWidgetText'),
$core->plugins->moduleInfo('postWidgetText', 'version'),
'>='
)) {
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
return null;
}
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
# Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, '2.6', '<', false)) {
throw new Exception(sprintf(
'%s requires Dotclear %s', 'postWidgetText', '2.6'
));
}
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
# Table is the same for plugins
# pollsFactory, postTask, postWidgetText
$s = new dbStruct($core->con,$core->prefix);
$s->post_option
->option_id ('bigint',0,false)
->post_id ('bigint',0,false)
->option_creadt ('timestamp',0,false,'now()')
->option_upddt ('timestamp',0,false,'now()')
->option_type ('varchar',32,false,"''")
->option_format ('varchar',32,false,"'xhtml'")
->option_lang ('varchar',5,true,null)
->option_title ('varchar',255,true,null)
->option_content ('text',0,true,null)
->option_content_xhtml ('text',0,false)
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
->index('idx_post_option_option','btree','option_id')
->index('idx_post_option_post','btree','post_id')
->index('idx_post_option_type','btree','option_type');
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
$si = new dbStruct($core->con,$core->prefix);
$changes = $si->synchronize($s);
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
# Settings
$core->blog->settings->addNamespace('postwidgettext');
$core->blog->settings->postwidgettext->put('postwidgettext_active',
true,'boolean','post widget text plugin enabled',false,true);
$core->blog->settings->postwidgettext->put('postwidgettext_importexport_active',
true,'boolean','activate import/export behaviors',false,true);
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
# Transfert records from old table to the new one
if ($core->getVersion('postWidgetText') !== null
&& version_compare($core->getVersion('postWidgetText'), '0.5', '<')
) {
require_once dirname(__FILE__).'/inc/patch.0.5.php';
}
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
# Set module version
$core->setVersion(
'postWidgetText',
$core->plugins->moduleInfo('postWidgetText', 'version')
);
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
return true;
2021-09-10 19:06:49 +00:00
}
catch (Exception $e) {
2021-09-10 19:18:51 +00:00
$core->error->add($e->getMessage());
2021-09-10 19:06:49 +00:00
2021-09-10 19:18:51 +00:00
return false;
}