2021-08-23 23:55:52 +00:00
< ? php
2021-09-02 18:35:25 +00:00
/**
* @ brief enhancePostContent , a plugin for Dotclear 2
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @ package Dotclear
* @ subpackage Plugin
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @ author Jean - Christian Denis and Contributors
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @ copyright Jean - Christian Denis
* @ copyright GPL - 2.0 https :// www . gnu . org / licenses / gpl - 2.0 . html
*/
2022-12-12 23:44:10 +00:00
if ( ! defined ( 'DC_CONTEXT_ADMIN' )) {
2022-11-13 20:30:48 +00:00
return null ;
}
2022-12-12 23:44:10 +00:00
class epcUpgrade
{
2022-12-13 20:39:18 +00:00
public static function growUp ()
2022-12-12 23:44:10 +00:00
{
$current = dcCore :: app () -> getVersion ( basename ( dirname ( '../' . __DIR__ )));
2022-12-13 20:39:18 +00:00
if ( $current && version_compare ( $current , '0.6.6' , '<=' )) {
2022-12-21 21:27:20 +00:00
self :: upTo00060607 ();
2022-12-12 23:44:10 +00:00
}
2022-12-13 20:39:18 +00:00
if ( $current && version_compare ( $current , '2021.10.06' , '<=' )) {
2022-12-21 21:27:20 +00:00
self :: upTo20211006 ();
2022-12-12 23:44:10 +00:00
}
2022-12-13 20:39:18 +00:00
if ( $current && version_compare ( $current , '2022.11.20' , '<=' )) {
2022-12-21 21:27:20 +00:00
self :: upTo20221120 ();
2021-08-24 20:05:23 +00:00
}
2021-10-31 22:22:34 +00:00
}
2022-12-13 20:39:18 +00:00
/**
* 0.6 . 6
2022-12-21 21:27:20 +00:00
*
2022-12-13 20:39:18 +00:00
* - filters move from settings to dedicated table
*/
2022-12-21 21:27:20 +00:00
private static function upTo00060607 ()
2022-12-12 23:44:10 +00:00
{
# Move old filters lists from settings to database
$f = dcCore :: app () -> con -> select ( 'SELECT * FROM ' . dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL " );
while ( $f -> fetch ()) {
if ( preg_match ( '#enhancePostContent_(.*?)List#' , $f -> setting_id , $m )) {
$curlist = @ unserialize ( $f -> setting_value );
if ( is_array ( $curlist )) {
foreach ( $curlist as $k => $v ) {
$cur = dcCore :: app () -> con -> openCursor ( dcCore :: app () -> prefix . initEnhancePostContent :: TABLE_NAME );
dcCore :: app () -> con -> writeLock ( dcCore :: app () -> prefix . initEnhancePostContent :: TABLE_NAME );
2021-10-31 22:22:34 +00:00
2022-12-12 23:44:10 +00:00
$cur -> epc_id = dcCore :: app () -> con -> select ( 'SELECT MAX(epc_id) FROM ' . dcCore :: app () -> prefix . initEnhancePostContent :: TABLE_NAME . ' ' ) -> f ( 0 ) + 1 ;
$cur -> blog_id = $f -> blog_id ;
$cur -> epc_filter = strtolower ( $m [ 1 ]);
$cur -> epc_key = $k ;
$cur -> epc_value = $v ;
2021-10-31 22:22:34 +00:00
2022-12-12 23:44:10 +00:00
$cur -> insert ();
dcCore :: app () -> con -> unlock ();
}
}
dcCore :: app () -> con -> execute ( 'DELETE FROM ' . dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME . " WHERE setting_id=' " . $f -> setting_id . " ' AND setting_ns='enhancePostContent' AND blog_id=' " . $f -> blog_id . " ' " );
}
}
}
2022-12-13 20:39:18 +00:00
/**
* 2021.10 . 06
2022-12-21 21:27:20 +00:00
*
2022-12-13 20:39:18 +00:00
* - filters change name to id
*/
2022-12-21 21:27:20 +00:00
private static function upTo20211006 ()
2022-12-12 23:44:10 +00:00
{
# Move old filter name to filter id
$rs = dcCore :: app () -> con -> select ( 'SELECT epc_id, epc_filter FROM ' . dcCore :: app () -> prefix . initEnhancePostContent :: TABLE_NAME );
while ( $rs -> fetch ()) {
$cur = dcCore :: app () -> con -> openCursor ( dcCore :: app () -> prefix . initEnhancePostContent :: TABLE_NAME );
$cur -> epc_filter = strtolower ( $rs -> epc_filter );
$cur -> update ( 'WHERE epc_id = ' . $rs -> epc_id . ' ' );
dcCore :: app () -> blog -> triggerBlog ();
}
2021-08-24 20:05:23 +00:00
}
2022-12-13 20:39:18 +00:00
/**
* 2022.11 . 20
*
2022-12-21 21:27:20 +00:00
* - setting id changes to shorter one ,
2022-12-13 20:39:18 +00:00
* - setting ns changes to abstract one ( no real changes ),
* - setting value change from serialize to json_encode ( if it ' s array )
*/
2022-12-21 21:27:20 +00:00
private static function upTo20221120 ()
2022-12-13 20:39:18 +00:00
{
// list of settings using serialize values to move to json
$ids = [
2022-12-21 21:27:20 +00:00
'allowedtplvalues' ,
'allowedpubpages' ,
2022-12-13 20:39:18 +00:00
];
2022-12-21 21:27:20 +00:00
foreach ( enhancePostContent :: getFilters () as $id => $f ) {
2022-12-13 20:39:18 +00:00
$ids [] = $id ;
}
// get all enhancePostContent settings
$record = dcCore :: app () -> con -> select (
'SELECT * FROM ' . dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME . ' ' .
" WHERE setting_ns = 'enhancePostContent' "
);
// update settings id, ns, value
while ( $record -> fetch ()) {
if ( preg_match ( '/^enhancePostContent_(.*?)$/' , $record -> setting_id , $match )) {
$cur = dcCore :: app () -> con -> openCursor ( dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME );
$cur -> setting_id = $match [ 1 ];
$cur -> setting_ns = basename ( dirname ( '../' . __DIR__ ));
if ( in_array ( $match [ 1 ], $ids )) {
$cur -> setting_value = json_encode ( unserialize ( $record -> setting_value ));
}
$cur -> update ( " WHERE setting_id = ' " . $record -> setting_id . " ' and setting_ns = 'enhancePostContent' " );
}
}
}
2021-11-01 09:33:43 +00:00
}