Dotclear


Ignore:
Timestamp:
02/05/16 15:12:03 (9 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use new setting type 'array' for some settings, addresses #1833

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/dbschema/upgrade.php

    r3138 r3159  
    479479                    $core->con->execute( 
    480480                         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'); 
    481488               } 
    482489 
     
    506513     return false; 
    507514} 
     515 
     516/** 
     517 * Convert old-fashion serialized array setting to new-fashion json encoded array 
     518 * @param  $ns      namespace 
     519 * @param  $setting setting name (id) 
     520 */ 
     521function settings2array($ns,$setting) 
     522{ 
     523     global $core; 
     524 
     525     $strReqSelect = 
     526          "SELECT setting_id,blog_id,setting_ns,setting_type,setting_value FROM ".$core->prefix."setting ". 
     527          "WHERE setting_id = '%s' ". 
     528          "AND setting_ns = '%s' ". 
     529          "AND setting_type = 'string'"; 
     530     $rs = $core->con->select(sprintf($strReqSelect,$setting,$ns)); 
     531     while ($rs->fetch()) { 
     532          $value = json_encode(unserialize($rs->setting_value)); 
     533          $rs2 = "UPDATE ".$core->prefix."setting ". 
     534               "SET setting_type='array', setting_value = '".$core->con->escape($value)."' ". 
     535               "WHERE setting_id='".$core->con->escape($rs->setting_id)."' ". 
     536               "AND setting_ns='".$core->con->escape($rs->setting_ns)."' "; 
     537          if ($rs->blog_id == '') { 
     538               $rs2 .= "AND blog_id IS null"; 
     539          } else { 
     540               $rs2 .= "AND blog_id = '".$core->con->escape($rs->blog_id)."'"; 
     541          } 
     542          $core->con->execute($rs2); 
     543     } 
     544} 
     545 
     546/** 
     547 * Convert old-fashion serialized array pref to new-fashion json encoded array 
     548 * @param  $ws      workspace 
     549 * @param  $pref    pref name (id) 
     550 */ 
     551function prefs2array($ws,$pref) 
     552{ 
     553     global $core; 
     554 
     555     $strReqSelect = 
     556          "SELECT pref_id,user_id,pref_ws,pref_type,pref_value FROM ".$core->prefix."pref ". 
     557          "WHERE pref_id = '%s' ". 
     558          "AND pref_ws = '%s' ". 
     559          "AND pref_type = 'string'"; 
     560     $rs = $core->con->select(sprintf($strReqSelect,$pref,$ns)); 
     561     while ($rs->fetch()) { 
     562          $value = json_encode(unserialize($rs->pref_value)); 
     563          $rs2 = "UPDATE ".$core->prefix."pref ". 
     564               "SET pref_type='array', pref_value = '".$core->con->escape($value)."' ". 
     565               "WHERE pref_id='".$core->con->escape($rs->pref_id)."' ". 
     566               "AND pref_ws='".$core->con->escape($rs->pref_ws)."' "; 
     567          if ($rs->user_id == '') { 
     568               $rs2 .= "AND user_id IS null"; 
     569          } else { 
     570               $rs2 .= "AND user_id = '".$core->con->escape($rs->user_id)."'"; 
     571          } 
     572          $core->con->execute($rs2); 
     573     } 
     574} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map