Dotclear

source: inc/dbschema/upgrade.php @ 3202:f3fa66f319ae

Revision 3202:f3fa66f319ae, 20.3 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Ensure recent media folders are stored in array type

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

Sites map