Changeset 3162:8a0aaa8b643b for inc/dbschema
- Timestamp:
- 02/07/16 10:40:47 (10 years ago)
- Branch:
- default
- Location:
- inc/dbschema
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/dbschema/upgrade-cli.php
r2566 r3162 31 31 32 32 require dirname(__FILE__).'/../prepend.php'; 33 require dirname(__FILE__).'/upgrade.php';34 33 35 34 echo "Starting upgrade process\n"; 36 35 $core->con->begin(); 37 36 try { 38 $changes = d otclearUpgrade($core);37 $changes = dcUpgrade::dotclearUpgrade($core); 39 38 } catch (Exception $e) { 40 39 $core->con->rollback(); -
inc/dbschema/upgrade.php
r3161 r3162 12 12 if (!defined('DC_RC_PATH')) { return; } 13 13 14 function dotclearUpgrade($core) 14 class dcUpgrade 15 15 { 16 $cleanup_sessions = false; // update it in a step that needed sessions to be removed 17 $version = $core->getVersion('core'); 18 19 if ($version === null) { 16 public static function dotclearUpgrade($core) 17 { 18 $cleanup_sessions = false; // update it in a step that needed sessions to be removed 19 $version = $core->getVersion('core'); 20 21 if ($version === null) { 22 return false; 23 } 24 25 if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev')) 26 { 27 try 28 { 29 if ($core->con->driver() == 'sqlite') { 30 return false; // Need to find a way to upgrade sqlite database 31 } 32 33 # Database upgrade 34 $_s = new dbStruct($core->con,$core->prefix); 35 require dirname(__FILE__).'/db-schema.php'; 36 37 $si = new dbStruct($core->con,$core->prefix); 38 $changes = $si->synchronize($_s); 39 40 /* Some other upgrades 41 ------------------------------------ */ 42 # Populate media_dir field (since 2.0-beta3.3) 43 if (version_compare($version,'2.0-beta3.3','<')) 44 { 45 $strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media '; 46 $rs_m = $core->con->select($strReq); 47 while($rs_m->fetch()) { 48 $cur = $core->con->openCursor($core->prefix.'media'); 49 $cur->media_dir = dirname($rs_m->media_file); 50 $cur->update('WHERE media_id = '.(integer) $rs_m->media_id); 51 } 52 } 53 54 if (version_compare($version,'2.0-beta7.3','<')) 55 { 56 # Blowup becomes default theme 57 $strReq = 'UPDATE '.$core->prefix.'setting '. 58 "SET setting_value = '%s' ". 59 "WHERE setting_id = 'theme' ". 60 "AND setting_value = '%s' ". 61 'AND blog_id IS NOT NULL '; 62 $core->con->execute(sprintf($strReq,'blueSilence','default')); 63 $core->con->execute(sprintf($strReq,'default','blowup')); 64 } 65 66 if (version_compare($version,'2.1-alpha2-r2383','<')) 67 { 68 $schema = dbSchema::init($core->con); 69 $schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title'); 70 71 # Reindex categories 72 $rs = $core->con->select( 73 'SELECT cat_id, cat_title, blog_id '. 74 'FROM '.$core->prefix.'category '. 75 'ORDER BY blog_id ASC , cat_position ASC ' 76 ); 77 $cat_blog = $rs->blog_id; 78 $i = 2; 79 while ($rs->fetch()) { 80 if ($cat_blog != $rs->blog_id) { 81 $i = 2; 82 } 83 $core->con->execute( 84 'UPDATE '.$core->prefix.'category SET ' 85 .'cat_lft = '.($i++).', cat_rgt = '.($i++).' '. 86 'WHERE cat_id = '.(integer) $rs->cat_id 87 ); 88 $cat_blog = $rs->blog_id; 89 } 90 } 91 92 if (version_compare($version,'2.1.6','<=')) 93 { 94 # ie7js has been upgraded 95 $ie7files = array ( 96 'ie7-base64.php ', 97 'ie7-content.htc', 98 'ie7-core.js', 99 'ie7-css2-selectors.js', 100 'ie7-css3-selectors.js', 101 'ie7-css-strict.js', 102 'ie7-dhtml.js', 103 'ie7-dynamic-attributes.js', 104 'ie7-fixed.js', 105 'ie7-graphics.js', 106 'ie7-html4.js', 107 'ie7-ie5.js', 108 'ie7-layout.js', 109 'ie7-load.htc', 110 'ie7-object.htc', 111 'ie7-overflow.js', 112 'ie7-quirks.js', 113 'ie7-server.css', 114 'ie7-standard-p.js', 115 'ie7-xml-extras.js' 116 ); 117 foreach ($ie7files as $f) { 118 @unlink(DC_ROOT.'/admin/js/ie7/'.$f); 119 } 120 } 121 122 if (version_compare($version,'2.2-alpha1-r3043','<')) 123 { 124 # metadata has been integrated to the core. 125 $core->plugins->loadModules(DC_PLUGINS_ROOT); 126 if ($core->plugins->moduleExists('metadata')) { 127 $core->plugins->deleteModule('metadata'); 128 } 129 130 # Tags template class has been renamed 131 $sqlstr = 132 'SELECT blog_id, setting_id, setting_value '. 133 'FROM '.$core->prefix.'setting '. 134 'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '. 135 'AND setting_ns = \'widgets\';'; 136 $rs = $core->con->select($sqlstr); 137 while ($rs->fetch()) { 138 $widgetsettings = base64_decode($rs->setting_value); 139 $widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings); 140 $cur = $core->con->openCursor($core->prefix.'setting'); 141 $cur->setting_value = base64_encode($widgetsettings); 142 $sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '. 143 'AND blog_id ' . 144 ($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\''); 145 $cur->update($sqlstr); 146 } 147 } 148 149 if (version_compare($version,'2.3','<')) 150 { 151 # Add global favorites 152 $init_fav = array(); 153 154 $init_fav['new_post'] = array('new_post','New entry','post.php', 155 'images/menu/edit.png','images/menu/edit-b.png', 156 'usage,contentadmin',null,null); 157 $init_fav['newpage'] = array('newpage','New page','plugin.php?p=pages&act=page', 158 'index.php?pf=pages/icon-np.png','index.php?pf=pages/icon-np-big.png', 159 'contentadmin,pages',null,null); 160 $init_fav['media'] = array('media','Media manager','media.php', 161 'images/menu/media.png','images/menu/media-b.png', 162 'media,media_admin',null,null); 163 $init_fav['widgets'] = array('widgets','Presentation widgets','plugin.php?p=widgets', 164 'index.php?pf=widgets/icon.png','index.php?pf=widgets/icon-big.png', 165 'admin',null,null); 166 $init_fav['blog_theme'] = array('blog_theme','Blog appearance','blog_theme.php', 167 'images/menu/themes.png','images/menu/blog-theme-b.png', 168 'admin',null,null); 169 170 $count = 0; 171 foreach ($init_fav as $k => $f) { 172 $t = array('name' => $f[0],'title' => $f[1],'url' => $f[2], 'small-icon' => $f[3], 173 'large-icon' => $f[4],'permissions' => $f[5],'id' => $f[6],'class' => $f[7]); 174 $sqlstr = 'INSERT INTO '.$core->prefix.'pref (pref_id, user_id, pref_ws, pref_value, pref_type, pref_label) VALUES ('. 175 '\''.sprintf("g%03s",$count).'\',NULL,\'favorites\',\''.serialize($t).'\',\'string\',NULL);'; 176 $core->con->execute($sqlstr); 177 $count++; 178 } 179 180 # A bit of housecleaning for no longer needed files 181 $remfiles = array ( 182 'admin/style/cat-bg.png', 183 'admin/style/footer-bg.png', 184 'admin/style/head-logo.png', 185 'admin/style/tab-bg.png', 186 'admin/style/tab-c-l.png', 187 'admin/style/tab-c-r.png', 188 'admin/style/tab-l-l.png', 189 'admin/style/tab-l-r.png', 190 'admin/style/tab-n-l.png', 191 'admin/style/tab-n-r.png', 192 'inc/clearbricks/_common.php', 193 'inc/clearbricks/common/lib.crypt.php', 194 'inc/clearbricks/common/lib.date.php', 195 'inc/clearbricks/common/lib.files.php', 196 'inc/clearbricks/common/lib.form.php', 197 'inc/clearbricks/common/lib.html.php', 198 'inc/clearbricks/common/lib.http.php', 199 'inc/clearbricks/common/lib.l10n.php', 200 'inc/clearbricks/common/lib.text.php', 201 'inc/clearbricks/common/tz.dat', 202 'inc/clearbricks/common/_main.php', 203 'inc/clearbricks/dblayer/class.cursor.php', 204 'inc/clearbricks/dblayer/class.mysql.php', 205 'inc/clearbricks/dblayer/class.pgsql.php', 206 'inc/clearbricks/dblayer/class.sqlite.php', 207 'inc/clearbricks/dblayer/dblayer.php', 208 'inc/clearbricks/dbschema/class.dbschema.php', 209 'inc/clearbricks/dbschema/class.dbstruct.php', 210 'inc/clearbricks/dbschema/class.mysql.dbschema.php', 211 'inc/clearbricks/dbschema/class.pgsql.dbschema.php', 212 'inc/clearbricks/dbschema/class.sqlite.dbschema.php', 213 'inc/clearbricks/diff/lib.diff.php', 214 'inc/clearbricks/diff/lib.unified.diff.php', 215 'inc/clearbricks/filemanager/class.filemanager.php', 216 'inc/clearbricks/html.filter/class.html.filter.php', 217 'inc/clearbricks/html.validator/class.html.validator.php', 218 'inc/clearbricks/image/class.image.meta.php', 219 'inc/clearbricks/image/class.image.tools.php', 220 'inc/clearbricks/mail/class.mail.php', 221 'inc/clearbricks/mail/class.socket.mail.php', 222 'inc/clearbricks/net/class.net.socket.php', 223 'inc/clearbricks/net.http/class.net.http.php', 224 'inc/clearbricks/net.http.feed/class.feed.parser.php', 225 'inc/clearbricks/net.http.feed/class.feed.reader.php', 226 'inc/clearbricks/net.xmlrpc/class.net.xmlrpc.php', 227 'inc/clearbricks/pager/class.pager.php', 228 'inc/clearbricks/rest/class.rest.php', 229 'inc/clearbricks/session.db/class.session.db.php', 230 'inc/clearbricks/template/class.template.php', 231 'inc/clearbricks/text.wiki2xhtml/class.wiki2xhtml.php', 232 'inc/clearbricks/url.handler/class.url.handler.php', 233 'inc/clearbricks/zip/class.unzip.php', 234 'inc/clearbricks/zip/class.zip.php', 235 'themes/default/tpl/.htaccess', 236 'themes/default/tpl/404.html', 237 'themes/default/tpl/archive.html', 238 'themes/default/tpl/archive_month.html', 239 'themes/default/tpl/category.html', 240 'themes/default/tpl/home.html', 241 'themes/default/tpl/post.html', 242 'themes/default/tpl/search.html', 243 'themes/default/tpl/tag.html', 244 'themes/default/tpl/tags.html', 245 'themes/default/tpl/user_head.html', 246 'themes/default/tpl/_flv_player.html', 247 'themes/default/tpl/_footer.html', 248 'themes/default/tpl/_head.html', 249 'themes/default/tpl/_mp3_player.html', 250 'themes/default/tpl/_top.html' 251 ); 252 $remfolders = array ( 253 'inc/clearbricks/common', 254 'inc/clearbricks/dblayer', 255 'inc/clearbricks/dbschema', 256 'inc/clearbricks/diff', 257 'inc/clearbricks/filemanager', 258 'inc/clearbricks/html.filter', 259 'inc/clearbricks/html.validator', 260 'inc/clearbricks/image', 261 'inc/clearbricks/mail', 262 'inc/clearbricks/net', 263 'inc/clearbricks/net.http', 264 'inc/clearbricks/net.http.feed', 265 'inc/clearbricks/net.xmlrpc', 266 'inc/clearbricks/pager', 267 'inc/clearbricks/rest', 268 'inc/clearbricks/session.db', 269 'inc/clearbricks/template', 270 'inc/clearbricks/text.wiki2xhtml', 271 'inc/clearbricks/url.handler', 272 'inc/clearbricks/zip', 273 'inc/clearbricks', 274 'themes/default/tpl' 275 ); 276 277 foreach ($remfiles as $f) { 278 @unlink(DC_ROOT.'/'.$f); 279 } 280 foreach ($remfolders as $f) { 281 @rmdir(DC_ROOT.'/'.$f); 282 } 283 } 284 285 if (version_compare($version,'2.3.1','<')) 286 { 287 # Remove unecessary file 288 @unlink(DC_ROOT.'/'.'inc/libs/clearbricks/.hgignore'); 289 } 290 291 if (version_compare($version,'2.4.0','<=')) 292 { 293 # setup media_exclusion 294 $strReq = 'UPDATE '.$core->prefix.'setting '. 295 "SET setting_value = '/\\.php\$/i' ". 296 "WHERE setting_id = 'media_exclusion' ". 297 "AND setting_value = '' "; 298 $core->con->execute($strReq); 299 } 300 301 if (version_compare($version,'2.5','<=')) 302 { 303 # Try to disable daInstaller plugin if it has been installed outside the default plugins directory 304 $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 305 $default = path::real(dirname(__FILE__).'/../../plugins/'); 306 foreach ($path as $root) 307 { 308 if (!is_dir($root) || !is_readable($root)) { 309 continue; 310 } 311 if (substr($root,-1) != '/') { 312 $root .= '/'; 313 } 314 if (($p = @dir($root)) === false) { 315 continue; 316 } 317 if(path::real($root) == $default) { 318 continue; 319 } 320 if (($d = @dir($root.'daInstaller')) === false) { 321 continue; 322 } 323 $f = $root.'/daInstaller/_disabled'; 324 if (!file_exists($f)) 325 { 326 @file_put_contents($f,''); 327 } 328 } 329 } 330 331 if (version_compare($version,'2.5.1','<=')) 332 { 333 // Flash enhanced upload no longer needed 334 @unlink(DC_ROOT.'/'.'inc/swf/swfupload.swf'); 335 } 336 337 if (version_compare($version,'2.6','<=')) 338 { 339 // README has been replaced by README.md and CONTRIBUTING.md 340 @unlink(DC_ROOT.'/'.'README'); 341 342 // trackbacks are now merged into posts 343 @unlink(DC_ROOT.'/'.'admin/trackbacks.php'); 344 345 # daInstaller has been integrated to the core. 346 # Try to remove it 347 $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 348 foreach ($path as $root) 349 { 350 if (!is_dir($root) || !is_readable($root)) { 351 continue; 352 } 353 if (substr($root,-1) != '/') { 354 $root .= '/'; 355 } 356 if (($p = @dir($root)) === false) { 357 continue; 358 } 359 if (($d = @dir($root.'daInstaller')) === false) { 360 continue; 361 } 362 files::deltree($root.'/daInstaller'); 363 } 364 365 # Some settings change, prepare db queries 366 $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; 367 $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; 368 $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; 369 370 $strReqSelect = 'SELECT count(1) FROM '.$core->prefix.'setting'; 371 $strReqSelect .= ' WHERE setting_id = \'%s\''; 372 $strReqSelect .= ' AND setting_ns = \'system\''; 373 $strReqSelect .= ' AND blog_id IS NULL'; 374 375 # Add date and time formats 376 $date_formats = array('%Y-%m-%d','%m/%d/%Y','%d/%m/%Y','%Y/%m/%d','%d.%m.%Y','%b %e %Y','%e %b %Y','%Y %b %e', 377 '%a, %Y-%m-%d','%a, %m/%d/%Y','%a, %d/%m/%Y','%a, %Y/%m/%d','%B %e, %Y','%e %B, %Y','%Y, %B %e','%e. %B %Y', 378 '%A, %B %e, %Y','%A, %e %B, %Y','%A, %Y, %B %e','%A, %Y, %B %e','%A, %e. %B %Y'); 379 $time_formats = array('%H:%M','%I:%M','%l:%M','%Hh%M','%Ih%M','%lh%M'); 380 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { 381 $date_formats = array_map(create_function('$f', 382 'return str_replace(\'%e\',\'%#d\',$f);' 383 ),$date_formats); 384 } 385 386 $rs = $core->con->select(sprintf($strReqSelect,'date_formats')); 387 if ($rs->f(0)==0) { 388 $strReq = sprintf($strReqFormat,'date_formats',serialize($date_formats),'Date formats examples'); 389 $core->con->execute($strReq); 390 } 391 $rs = $core->con->select(sprintf($strReqSelect,'time_formats')); 392 if ($rs->f(0)==0) { 393 $strReq = sprintf($strReqFormat,'time_formats',serialize($time_formats),'Time formats examples'); 394 $core->con->execute($strReq); 395 } 396 397 # Add repository URL for themes and plugins as daInstaller move to core 398 $rs = $core->con->select(sprintf($strReqSelect,'store_plugin_url')); 399 if ($rs->f(0)==0) { 400 $strReq = sprintf($strReqFormat,'store_plugin_url','http://update.dotaddict.org/dc2/plugins.xml','Plugins XML feed location'); 401 $core->con->execute($strReq); 402 } 403 $rs = $core->con->select(sprintf($strReqSelect,'store_theme_url')); 404 if ($rs->f(0)==0) { 405 $strReq = sprintf($strReqFormat,'store_theme_url','http://update.dotaddict.org/dc2/themes.xml','Themes XML feed location'); 406 $core->con->execute($strReq); 407 } 408 } 409 410 if (version_compare($version,'2.7','<=')) 411 { 412 # Some new settings should be initialized, prepare db queries 413 $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; 414 $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; 415 $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; 416 417 $strReqCount = 'SELECT count(1) FROM '.$core->prefix.'setting'; 418 $strReqCount .= ' WHERE setting_id = \'%s\''; 419 $strReqCount .= ' AND setting_ns = \'system\''; 420 $strReqCount .= ' AND blog_id IS NULL'; 421 422 $strReqSelect = 'SELECT setting_value FROM '.$core->prefix.'setting'; 423 $strReqSelect .= ' WHERE setting_id = \'%s\''; 424 $strReqSelect .= ' AND setting_ns = \'system\''; 425 $strReqSelect .= ' AND blog_id IS NULL'; 426 427 # Add nb of posts for home (first page), copying nb of posts on every page 428 $rs = $core->con->select(sprintf($strReqCount,'nb_post_for_home')); 429 if ($rs->f(0)==0) { 430 $rs = $core->con->select(sprintf($strReqSelect,'nb_post_per_page')); 431 $strReq = sprintf($strReqFormat,'nb_post_for_home',$rs->f(0),'Nb of posts on home (first page only)'); 432 $core->con->execute($strReq); 433 } 434 } 435 436 if (version_compare($version,'2.8.1','<=')) 437 { 438 # switch from jQuery 1.11.1 to 1.11.2 439 $strReq = 'UPDATE '.$core->prefix.'setting '. 440 " SET setting_value = '1.11.3' ". 441 " WHERE setting_id = 'jquery_version' ". 442 " AND setting_ns = 'system' ". 443 " AND setting_value = '1.11.1' "; 444 $core->con->execute($strReq); 445 # setup media_exclusion (cope with php, php5, php7, … rather than only .php) 446 $strReq = 'UPDATE '.$core->prefix.'setting '. 447 " SET setting_value = '/\\.php[0-9]*\$/i' ". 448 " WHERE setting_id = 'media_exclusion' ". 449 " AND setting_ns = 'system' ". 450 " AND setting_value = '/\\.php\$/i' "; 451 $core->con->execute($strReq); 452 # Some new settings should be initialized, prepare db queries 453 $strReq = 'INSERT INTO '.$core->prefix.'setting'. 454 ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. 455 ' VALUES(\'%s\',\'system\',\'%s\',\'boolean\',\'%s\')'; 456 $core->con->execute(sprintf($strReq,'no_search','0','Disable internal search system')); 457 } 458 459 if (version_compare($version,'2.8.2','<=')) 460 { 461 # Update flie exclusion upload regex 462 $strReq = 'UPDATE '.$core->prefix.'setting '. 463 " SET setting_value = '/\\.(phps?|pht(ml)?|phl)[0-9]*\$/i' ". 464 " WHERE setting_id = 'media_exclusion' ". 465 " AND setting_ns = 'system' ". 466 " AND (setting_value = '/\\.php[0-9]*\$/i' ". 467 " OR setting_value = '/\\.php\$/i') "; 468 $core->con->execute($strReq); 469 } 470 471 if (version_compare($version,'2.9','<=')) 472 { 473 # Some new settings should be initialized, prepare db queries 474 $strReq = 'INSERT INTO '.$core->prefix.'setting'. 475 ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. 476 ' VALUES(\'%s\',\'system\',\'%s\',\'%s\',\'%s\')'; 477 $core->con->execute( 478 sprintf($strReq,'media_video_width','400','integer','Media video insertion width')); 479 $core->con->execute( 480 sprintf($strReq,'media_video_height','300','integer','Media video insertion height')); 481 $core->con->execute( 482 sprintf($strReq,'media_flash_fallback','1','boolean','Flash player fallback for audio and video media')); 483 484 # Some settings and prefs should be moved from string to array 485 self::settings2array('system','date_formats'); 486 self::settings2array('system','time_formats'); 487 self::settings2array('antispam','antispam_filters'); 488 self::settings2array('pings','pings_uris'); 489 self::settings2array('system','simpleMenu'); 490 self::prefs2array('dashboard','favorites'); 491 self::prefs2array('interface','media_last_dirs'); 492 } 493 494 $core->setVersion('core',DC_VERSION); 495 $core->blogDefaults(); 496 497 # Drop content from session table if changes or if needed 498 if ($changes != 0 || $cleanup_sessions) { 499 $core->con->execute('DELETE FROM '.$core->prefix.'session '); 500 } 501 502 # Empty templates cache directory 503 try { 504 $core->emptyTemplatesCache(); 505 } catch (Exception $e) {} 506 507 return $changes; 508 } 509 catch (Exception $e) 510 { 511 throw new Exception(__('Something went wrong with auto upgrade:'). 512 ' '.$e->getMessage()); 513 } 514 } 515 516 # No upgrade? 20 517 return false; 21 518 } 22 519 23 if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev')) 520 /** 521 * Convert old-fashion serialized array setting to new-fashion json encoded array 522 * @param $ns namespace 523 * @param $setting setting name (id) 524 */ 525 public static function settings2array($ns,$setting) 24 526 { 25 try 26 { 27 if ($core->con->driver() == 'sqlite') { 28 return false; // Need to find a way to upgrade sqlite database 527 global $core; 528 529 $strReqSelect = 530 "SELECT setting_id,blog_id,setting_ns,setting_type,setting_value FROM ".$core->prefix."setting ". 531 "WHERE setting_id = '%s' ". 532 "AND setting_ns = '%s' ". 533 "AND setting_type = 'string'"; 534 $rs = $core->con->select(sprintf($strReqSelect,$setting,$ns)); 535 while ($rs->fetch()) { 536 $value = json_encode(unserialize($rs->setting_value)); 537 $rs2 = "UPDATE ".$core->prefix."setting ". 538 "SET setting_type='array', setting_value = '".$core->con->escape($value)."' ". 539 "WHERE setting_id='".$core->con->escape($rs->setting_id)."' ". 540 "AND setting_ns='".$core->con->escape($rs->setting_ns)."' "; 541 if ($rs->blog_id == '') { 542 $rs2 .= "AND blog_id IS null"; 543 } else { 544 $rs2 .= "AND blog_id = '".$core->con->escape($rs->blog_id)."'"; 29 545 } 30 31 # Database upgrade 32 $_s = new dbStruct($core->con,$core->prefix); 33 require dirname(__FILE__).'/db-schema.php'; 34 35 $si = new dbStruct($core->con,$core->prefix); 36 $changes = $si->synchronize($_s); 37 38 /* Some other upgrades 39 ------------------------------------ */ 40 # Populate media_dir field (since 2.0-beta3.3) 41 if (version_compare($version,'2.0-beta3.3','<')) 42 { 43 $strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media '; 44 $rs_m = $core->con->select($strReq); 45 while($rs_m->fetch()) { 46 $cur = $core->con->openCursor($core->prefix.'media'); 47 $cur->media_dir = dirname($rs_m->media_file); 48 $cur->update('WHERE media_id = '.(integer) $rs_m->media_id); 49 } 50 } 51 52 if (version_compare($version,'2.0-beta7.3','<')) 53 { 54 # Blowup becomes default theme 55 $strReq = 'UPDATE '.$core->prefix.'setting '. 56 "SET setting_value = '%s' ". 57 "WHERE setting_id = 'theme' ". 58 "AND setting_value = '%s' ". 59 'AND blog_id IS NOT NULL '; 60 $core->con->execute(sprintf($strReq,'blueSilence','default')); 61 $core->con->execute(sprintf($strReq,'default','blowup')); 62 } 63 64 if (version_compare($version,'2.1-alpha2-r2383','<')) 65 { 66 $schema = dbSchema::init($core->con); 67 $schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title'); 68 69 # Reindex categories 70 $rs = $core->con->select( 71 'SELECT cat_id, cat_title, blog_id '. 72 'FROM '.$core->prefix.'category '. 73 'ORDER BY blog_id ASC , cat_position ASC ' 74 ); 75 $cat_blog = $rs->blog_id; 76 $i = 2; 77 while ($rs->fetch()) { 78 if ($cat_blog != $rs->blog_id) { 79 $i = 2; 80 } 81 $core->con->execute( 82 'UPDATE '.$core->prefix.'category SET ' 83 .'cat_lft = '.($i++).', cat_rgt = '.($i++).' '. 84 'WHERE cat_id = '.(integer) $rs->cat_id 85 ); 86 $cat_blog = $rs->blog_id; 87 } 88 } 89 90 if (version_compare($version,'2.1.6','<=')) 91 { 92 # ie7js has been upgraded 93 $ie7files = array ( 94 'ie7-base64.php ', 95 'ie7-content.htc', 96 'ie7-core.js', 97 'ie7-css2-selectors.js', 98 'ie7-css3-selectors.js', 99 'ie7-css-strict.js', 100 'ie7-dhtml.js', 101 'ie7-dynamic-attributes.js', 102 'ie7-fixed.js', 103 'ie7-graphics.js', 104 'ie7-html4.js', 105 'ie7-ie5.js', 106 'ie7-layout.js', 107 'ie7-load.htc', 108 'ie7-object.htc', 109 'ie7-overflow.js', 110 'ie7-quirks.js', 111 'ie7-server.css', 112 'ie7-standard-p.js', 113 'ie7-xml-extras.js' 114 ); 115 foreach ($ie7files as $f) { 116 @unlink(DC_ROOT.'/admin/js/ie7/'.$f); 117 } 118 } 119 120 if (version_compare($version,'2.2-alpha1-r3043','<')) 121 { 122 # metadata has been integrated to the core. 123 $core->plugins->loadModules(DC_PLUGINS_ROOT); 124 if ($core->plugins->moduleExists('metadata')) { 125 $core->plugins->deleteModule('metadata'); 126 } 127 128 # Tags template class has been renamed 129 $sqlstr = 130 'SELECT blog_id, setting_id, setting_value '. 131 'FROM '.$core->prefix.'setting '. 132 'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '. 133 'AND setting_ns = \'widgets\';'; 134 $rs = $core->con->select($sqlstr); 135 while ($rs->fetch()) { 136 $widgetsettings = base64_decode($rs->setting_value); 137 $widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings); 138 $cur = $core->con->openCursor($core->prefix.'setting'); 139 $cur->setting_value = base64_encode($widgetsettings); 140 $sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '. 141 'AND blog_id ' . 142 ($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\''); 143 $cur->update($sqlstr); 144 } 145 } 146 147 if (version_compare($version,'2.3','<')) 148 { 149 # Add global favorites 150 $init_fav = array(); 151 152 $init_fav['new_post'] = array('new_post','New entry','post.php', 153 'images/menu/edit.png','images/menu/edit-b.png', 154 'usage,contentadmin',null,null); 155 $init_fav['newpage'] = array('newpage','New page','plugin.php?p=pages&act=page', 156 'index.php?pf=pages/icon-np.png','index.php?pf=pages/icon-np-big.png', 157 'contentadmin,pages',null,null); 158 $init_fav['media'] = array('media','Media manager','media.php', 159 'images/menu/media.png','images/menu/media-b.png', 160 'media,media_admin',null,null); 161 $init_fav['widgets'] = array('widgets','Presentation widgets','plugin.php?p=widgets', 162 'index.php?pf=widgets/icon.png','index.php?pf=widgets/icon-big.png', 163 'admin',null,null); 164 $init_fav['blog_theme'] = array('blog_theme','Blog appearance','blog_theme.php', 165 'images/menu/themes.png','images/menu/blog-theme-b.png', 166 'admin',null,null); 167 168 $count = 0; 169 foreach ($init_fav as $k => $f) { 170 $t = array('name' => $f[0],'title' => $f[1],'url' => $f[2], 'small-icon' => $f[3], 171 'large-icon' => $f[4],'permissions' => $f[5],'id' => $f[6],'class' => $f[7]); 172 $sqlstr = 'INSERT INTO '.$core->prefix.'pref (pref_id, user_id, pref_ws, pref_value, pref_type, pref_label) VALUES ('. 173 '\''.sprintf("g%03s",$count).'\',NULL,\'favorites\',\''.serialize($t).'\',\'string\',NULL);'; 174 $core->con->execute($sqlstr); 175 $count++; 176 } 177 178 # A bit of housecleaning for no longer needed files 179 $remfiles = array ( 180 'admin/style/cat-bg.png', 181 'admin/style/footer-bg.png', 182 'admin/style/head-logo.png', 183 'admin/style/tab-bg.png', 184 'admin/style/tab-c-l.png', 185 'admin/style/tab-c-r.png', 186 'admin/style/tab-l-l.png', 187 'admin/style/tab-l-r.png', 188 'admin/style/tab-n-l.png', 189 'admin/style/tab-n-r.png', 190 'inc/clearbricks/_common.php', 191 'inc/clearbricks/common/lib.crypt.php', 192 'inc/clearbricks/common/lib.date.php', 193 'inc/clearbricks/common/lib.files.php', 194 'inc/clearbricks/common/lib.form.php', 195 'inc/clearbricks/common/lib.html.php', 196 'inc/clearbricks/common/lib.http.php', 197 'inc/clearbricks/common/lib.l10n.php', 198 'inc/clearbricks/common/lib.text.php', 199 'inc/clearbricks/common/tz.dat', 200 'inc/clearbricks/common/_main.php', 201 'inc/clearbricks/dblayer/class.cursor.php', 202 'inc/clearbricks/dblayer/class.mysql.php', 203 'inc/clearbricks/dblayer/class.pgsql.php', 204 'inc/clearbricks/dblayer/class.sqlite.php', 205 'inc/clearbricks/dblayer/dblayer.php', 206 'inc/clearbricks/dbschema/class.dbschema.php', 207 'inc/clearbricks/dbschema/class.dbstruct.php', 208 'inc/clearbricks/dbschema/class.mysql.dbschema.php', 209 'inc/clearbricks/dbschema/class.pgsql.dbschema.php', 210 'inc/clearbricks/dbschema/class.sqlite.dbschema.php', 211 'inc/clearbricks/diff/lib.diff.php', 212 'inc/clearbricks/diff/lib.unified.diff.php', 213 'inc/clearbricks/filemanager/class.filemanager.php', 214 'inc/clearbricks/html.filter/class.html.filter.php', 215 'inc/clearbricks/html.validator/class.html.validator.php', 216 'inc/clearbricks/image/class.image.meta.php', 217 'inc/clearbricks/image/class.image.tools.php', 218 'inc/clearbricks/mail/class.mail.php', 219 'inc/clearbricks/mail/class.socket.mail.php', 220 'inc/clearbricks/net/class.net.socket.php', 221 'inc/clearbricks/net.http/class.net.http.php', 222 'inc/clearbricks/net.http.feed/class.feed.parser.php', 223 'inc/clearbricks/net.http.feed/class.feed.reader.php', 224 'inc/clearbricks/net.xmlrpc/class.net.xmlrpc.php', 225 'inc/clearbricks/pager/class.pager.php', 226 'inc/clearbricks/rest/class.rest.php', 227 'inc/clearbricks/session.db/class.session.db.php', 228 'inc/clearbricks/template/class.template.php', 229 'inc/clearbricks/text.wiki2xhtml/class.wiki2xhtml.php', 230 'inc/clearbricks/url.handler/class.url.handler.php', 231 'inc/clearbricks/zip/class.unzip.php', 232 'inc/clearbricks/zip/class.zip.php', 233 'themes/default/tpl/.htaccess', 234 'themes/default/tpl/404.html', 235 'themes/default/tpl/archive.html', 236 'themes/default/tpl/archive_month.html', 237 'themes/default/tpl/category.html', 238 'themes/default/tpl/home.html', 239 'themes/default/tpl/post.html', 240 'themes/default/tpl/search.html', 241 'themes/default/tpl/tag.html', 242 'themes/default/tpl/tags.html', 243 'themes/default/tpl/user_head.html', 244 'themes/default/tpl/_flv_player.html', 245 'themes/default/tpl/_footer.html', 246 'themes/default/tpl/_head.html', 247 'themes/default/tpl/_mp3_player.html', 248 'themes/default/tpl/_top.html' 249 ); 250 $remfolders = array ( 251 'inc/clearbricks/common', 252 'inc/clearbricks/dblayer', 253 'inc/clearbricks/dbschema', 254 'inc/clearbricks/diff', 255 'inc/clearbricks/filemanager', 256 'inc/clearbricks/html.filter', 257 'inc/clearbricks/html.validator', 258 'inc/clearbricks/image', 259 'inc/clearbricks/mail', 260 'inc/clearbricks/net', 261 'inc/clearbricks/net.http', 262 'inc/clearbricks/net.http.feed', 263 'inc/clearbricks/net.xmlrpc', 264 'inc/clearbricks/pager', 265 'inc/clearbricks/rest', 266 'inc/clearbricks/session.db', 267 'inc/clearbricks/template', 268 'inc/clearbricks/text.wiki2xhtml', 269 'inc/clearbricks/url.handler', 270 'inc/clearbricks/zip', 271 'inc/clearbricks', 272 'themes/default/tpl' 273 ); 274 275 foreach ($remfiles as $f) { 276 @unlink(DC_ROOT.'/'.$f); 277 } 278 foreach ($remfolders as $f) { 279 @rmdir(DC_ROOT.'/'.$f); 280 } 281 } 282 283 if (version_compare($version,'2.3.1','<')) 284 { 285 # Remove unecessary file 286 @unlink(DC_ROOT.'/'.'inc/libs/clearbricks/.hgignore'); 287 } 288 289 if (version_compare($version,'2.4.0','<=')) 290 { 291 # setup media_exclusion 292 $strReq = 'UPDATE '.$core->prefix.'setting '. 293 "SET setting_value = '/\\.php\$/i' ". 294 "WHERE setting_id = 'media_exclusion' ". 295 "AND setting_value = '' "; 296 $core->con->execute($strReq); 297 } 298 299 if (version_compare($version,'2.5','<=')) 300 { 301 # Try to disable daInstaller plugin if it has been installed outside the default plugins directory 302 $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 303 $default = path::real(dirname(__FILE__).'/../../plugins/'); 304 foreach ($path as $root) 305 { 306 if (!is_dir($root) || !is_readable($root)) { 307 continue; 308 } 309 if (substr($root,-1) != '/') { 310 $root .= '/'; 311 } 312 if (($p = @dir($root)) === false) { 313 continue; 314 } 315 if(path::real($root) == $default) { 316 continue; 317 } 318 if (($d = @dir($root.'daInstaller')) === false) { 319 continue; 320 } 321 $f = $root.'/daInstaller/_disabled'; 322 if (!file_exists($f)) 323 { 324 @file_put_contents($f,''); 325 } 326 } 327 } 328 329 if (version_compare($version,'2.5.1','<=')) 330 { 331 // Flash enhanced upload no longer needed 332 @unlink(DC_ROOT.'/'.'inc/swf/swfupload.swf'); 333 } 334 335 if (version_compare($version,'2.6','<=')) 336 { 337 // README has been replaced by README.md and CONTRIBUTING.md 338 @unlink(DC_ROOT.'/'.'README'); 339 340 // trackbacks are now merged into posts 341 @unlink(DC_ROOT.'/'.'admin/trackbacks.php'); 342 343 # daInstaller has been integrated to the core. 344 # Try to remove it 345 $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 346 foreach ($path as $root) 347 { 348 if (!is_dir($root) || !is_readable($root)) { 349 continue; 350 } 351 if (substr($root,-1) != '/') { 352 $root .= '/'; 353 } 354 if (($p = @dir($root)) === false) { 355 continue; 356 } 357 if (($d = @dir($root.'daInstaller')) === false) { 358 continue; 359 } 360 files::deltree($root.'/daInstaller'); 361 } 362 363 # Some settings change, prepare db queries 364 $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; 365 $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; 366 $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; 367 368 $strReqSelect = 'SELECT count(1) FROM '.$core->prefix.'setting'; 369 $strReqSelect .= ' WHERE setting_id = \'%s\''; 370 $strReqSelect .= ' AND setting_ns = \'system\''; 371 $strReqSelect .= ' AND blog_id IS NULL'; 372 373 # Add date and time formats 374 $date_formats = array('%Y-%m-%d','%m/%d/%Y','%d/%m/%Y','%Y/%m/%d','%d.%m.%Y','%b %e %Y','%e %b %Y','%Y %b %e', 375 '%a, %Y-%m-%d','%a, %m/%d/%Y','%a, %d/%m/%Y','%a, %Y/%m/%d','%B %e, %Y','%e %B, %Y','%Y, %B %e','%e. %B %Y', 376 '%A, %B %e, %Y','%A, %e %B, %Y','%A, %Y, %B %e','%A, %Y, %B %e','%A, %e. %B %Y'); 377 $time_formats = array('%H:%M','%I:%M','%l:%M','%Hh%M','%Ih%M','%lh%M'); 378 if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { 379 $date_formats = array_map(create_function('$f', 380 'return str_replace(\'%e\',\'%#d\',$f);' 381 ),$date_formats); 382 } 383 384 $rs = $core->con->select(sprintf($strReqSelect,'date_formats')); 385 if ($rs->f(0)==0) { 386 $strReq = sprintf($strReqFormat,'date_formats',serialize($date_formats),'Date formats examples'); 387 $core->con->execute($strReq); 388 } 389 $rs = $core->con->select(sprintf($strReqSelect,'time_formats')); 390 if ($rs->f(0)==0) { 391 $strReq = sprintf($strReqFormat,'time_formats',serialize($time_formats),'Time formats examples'); 392 $core->con->execute($strReq); 393 } 394 395 # Add repository URL for themes and plugins as daInstaller move to core 396 $rs = $core->con->select(sprintf($strReqSelect,'store_plugin_url')); 397 if ($rs->f(0)==0) { 398 $strReq = sprintf($strReqFormat,'store_plugin_url','http://update.dotaddict.org/dc2/plugins.xml','Plugins XML feed location'); 399 $core->con->execute($strReq); 400 } 401 $rs = $core->con->select(sprintf($strReqSelect,'store_theme_url')); 402 if ($rs->f(0)==0) { 403 $strReq = sprintf($strReqFormat,'store_theme_url','http://update.dotaddict.org/dc2/themes.xml','Themes XML feed location'); 404 $core->con->execute($strReq); 405 } 406 } 407 408 if (version_compare($version,'2.7','<=')) 409 { 410 # Some new settings should be initialized, prepare db queries 411 $strReqFormat = 'INSERT INTO '.$core->prefix.'setting'; 412 $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'; 413 $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')'; 414 415 $strReqCount = 'SELECT count(1) FROM '.$core->prefix.'setting'; 416 $strReqCount .= ' WHERE setting_id = \'%s\''; 417 $strReqCount .= ' AND setting_ns = \'system\''; 418 $strReqCount .= ' AND blog_id IS NULL'; 419 420 $strReqSelect = 'SELECT setting_value FROM '.$core->prefix.'setting'; 421 $strReqSelect .= ' WHERE setting_id = \'%s\''; 422 $strReqSelect .= ' AND setting_ns = \'system\''; 423 $strReqSelect .= ' AND blog_id IS NULL'; 424 425 # Add nb of posts for home (first page), copying nb of posts on every page 426 $rs = $core->con->select(sprintf($strReqCount,'nb_post_for_home')); 427 if ($rs->f(0)==0) { 428 $rs = $core->con->select(sprintf($strReqSelect,'nb_post_per_page')); 429 $strReq = sprintf($strReqFormat,'nb_post_for_home',$rs->f(0),'Nb of posts on home (first page only)'); 430 $core->con->execute($strReq); 431 } 432 } 433 434 if (version_compare($version,'2.8.1','<=')) 435 { 436 # switch from jQuery 1.11.1 to 1.11.2 437 $strReq = 'UPDATE '.$core->prefix.'setting '. 438 " SET setting_value = '1.11.3' ". 439 " WHERE setting_id = 'jquery_version' ". 440 " AND setting_ns = 'system' ". 441 " AND setting_value = '1.11.1' "; 442 $core->con->execute($strReq); 443 # setup media_exclusion (cope with php, php5, php7, … rather than only .php) 444 $strReq = 'UPDATE '.$core->prefix.'setting '. 445 " SET setting_value = '/\\.php[0-9]*\$/i' ". 446 " WHERE setting_id = 'media_exclusion' ". 447 " AND setting_ns = 'system' ". 448 " AND setting_value = '/\\.php\$/i' "; 449 $core->con->execute($strReq); 450 # Some new settings should be initialized, prepare db queries 451 $strReq = 'INSERT INTO '.$core->prefix.'setting'. 452 ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. 453 ' VALUES(\'%s\',\'system\',\'%s\',\'boolean\',\'%s\')'; 454 $core->con->execute(sprintf($strReq,'no_search','0','Disable internal search system')); 455 } 456 457 if (version_compare($version,'2.8.2','<=')) 458 { 459 # Update flie exclusion upload regex 460 $strReq = 'UPDATE '.$core->prefix.'setting '. 461 " SET setting_value = '/\\.(phps?|pht(ml)?|phl)[0-9]*\$/i' ". 462 " WHERE setting_id = 'media_exclusion' ". 463 " AND setting_ns = 'system' ". 464 " AND (setting_value = '/\\.php[0-9]*\$/i' ". 465 " OR setting_value = '/\\.php\$/i') "; 466 $core->con->execute($strReq); 467 } 468 469 if (version_compare($version,'2.9','<=')) 470 { 471 # Some new settings should be initialized, prepare db queries 472 $strReq = 'INSERT INTO '.$core->prefix.'setting'. 473 ' (setting_id,setting_ns,setting_value,setting_type,setting_label)'. 474 ' VALUES(\'%s\',\'system\',\'%s\',\'%s\',\'%s\')'; 475 $core->con->execute( 476 sprintf($strReq,'media_video_width','400','integer','Media video insertion width')); 477 $core->con->execute( 478 sprintf($strReq,'media_video_height','300','integer','Media video insertion height')); 479 $core->con->execute( 480 sprintf($strReq,'media_flash_fallback','1','boolean','Flash player fallback for audio and video media')); 481 482 # Some settings and prefs should be moved from string to array 483 settings2array('system','date_formats'); 484 settings2array('system','time_formats'); 485 settings2array('antispam','antispam_filters'); 486 settings2array('pings','pings_uris'); 487 settings2array('system','simpleMenu'); 488 prefs2array('dashboard','favorites'); 489 prefs2array('interface','media_last_dirs'); 490 } 491 492 $core->setVersion('core',DC_VERSION); 493 $core->blogDefaults(); 494 495 # Drop content from session table if changes or if needed 496 if ($changes != 0 || $cleanup_sessions) { 497 $core->con->execute('DELETE FROM '.$core->prefix.'session '); 498 } 499 500 # Empty templates cache directory 501 try { 502 $core->emptyTemplatesCache(); 503 } catch (Exception $e) {} 504 505 return $changes; 506 } 507 catch (Exception $e) 508 { 509 throw new Exception(__('Something went wrong with auto upgrade:'). 510 ' '.$e->getMessage()); 546 $core->con->execute($rs2); 511 547 } 512 548 } 513 549 514 # No upgrade? 515 return false; 516 } 517 518 /** 519 * Convert old-fashion serialized array setting to new-fashion json encoded array 520 * @param $ns namespace 521 * @param $setting setting name (id) 522 */ 523 function settings2array($ns,$setting) 524 { 525 global $core; 526 527 $strReqSelect = 528 "SELECT setting_id,blog_id,setting_ns,setting_type,setting_value FROM ".$core->prefix."setting ". 529 "WHERE setting_id = '%s' ". 530 "AND setting_ns = '%s' ". 531 "AND setting_type = 'string'"; 532 $rs = $core->con->select(sprintf($strReqSelect,$setting,$ns)); 533 while ($rs->fetch()) { 534 $value = json_encode(unserialize($rs->setting_value)); 535 $rs2 = "UPDATE ".$core->prefix."setting ". 536 "SET setting_type='array', setting_value = '".$core->con->escape($value)."' ". 537 "WHERE setting_id='".$core->con->escape($rs->setting_id)."' ". 538 "AND setting_ns='".$core->con->escape($rs->setting_ns)."' "; 539 if ($rs->blog_id == '') { 540 $rs2 .= "AND blog_id IS null"; 541 } else { 542 $rs2 .= "AND blog_id = '".$core->con->escape($rs->blog_id)."'"; 550 /** 551 * Convert old-fashion serialized array pref to new-fashion json encoded array 552 * @param $ws workspace 553 * @param $pref pref name (id) 554 */ 555 public static function prefs2array($ws,$pref) 556 { 557 global $core; 558 559 $strReqSelect = 560 "SELECT pref_id,user_id,pref_ws,pref_type,pref_value FROM ".$core->prefix."pref ". 561 "WHERE pref_id = '%s' ". 562 "AND pref_ws = '%s' ". 563 "AND pref_type = 'string'"; 564 $rs = $core->con->select(sprintf($strReqSelect,$pref,$ws)); 565 while ($rs->fetch()) { 566 $value = json_encode(unserialize($rs->pref_value)); 567 $rs2 = "UPDATE ".$core->prefix."pref ". 568 "SET pref_type='array', pref_value = '".$core->con->escape($value)."' ". 569 "WHERE pref_id='".$core->con->escape($rs->pref_id)."' ". 570 "AND pref_ws='".$core->con->escape($rs->pref_ws)."' "; 571 if ($rs->user_id == '') { 572 $rs2 .= "AND user_id IS null"; 573 } else { 574 $rs2 .= "AND user_id = '".$core->con->escape($rs->user_id)."'"; 575 } 576 $core->con->execute($rs2); 543 577 } 544 $core->con->execute($rs2);545 578 } 546 579 } 547 548 /**549 * Convert old-fashion serialized array pref to new-fashion json encoded array550 * @param $ws workspace551 * @param $pref pref name (id)552 */553 function prefs2array($ws,$pref)554 {555 global $core;556 557 $strReqSelect =558 "SELECT pref_id,user_id,pref_ws,pref_type,pref_value FROM ".$core->prefix."pref ".559 "WHERE pref_id = '%s' ".560 "AND pref_ws = '%s' ".561 "AND pref_type = 'string'";562 $rs = $core->con->select(sprintf($strReqSelect,$pref,$ws));563 while ($rs->fetch()) {564 $value = json_encode(unserialize($rs->pref_value));565 $rs2 = "UPDATE ".$core->prefix."pref ".566 "SET pref_type='array', pref_value = '".$core->con->escape($value)."' ".567 "WHERE pref_id='".$core->con->escape($rs->pref_id)."' ".568 "AND pref_ws='".$core->con->escape($rs->pref_ws)."' ";569 if ($rs->user_id == '') {570 $rs2 .= "AND user_id IS null";571 } else {572 $rs2 .= "AND user_id = '".$core->con->escape($rs->user_id)."'";573 }574 $core->con->execute($rs2);575 }576 }
Note: See TracChangeset
for help on using the changeset viewer.