Dotclear

source: inc/dbschema/upgrade.php @ 2295:f20eb5bb555b

Revision 2295:f20eb5bb555b, 14.0 KB checked in by Nicolas <nikrou77@…>, 12 years ago (diff)

Add fixes when using %e modifier for windows dates.
Closes #1714, closes #1744

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
14function dotclearUpgrade($core)
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) {
20          return false;
21     }
22     
23     if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev'))
24     {
25          try
26          {
27               if ($core->con->driver() == 'sqlite') {
28                    throw new Exception(__('SQLite Database Schema cannot be upgraded.'));
29               }
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&amp;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                    # add new settings for date and time formats
364                    $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',
365                    '%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',
366                    '%A, %B %e, %Y','%A, %e %B, %Y','%A, %Y, %B %e','%A, %Y, %B %e','%A, %e. %B %Y');
367                    $time_formats = array('%H:%M','%I:%M','%l:%M','%Hh%M','%Ih%M','%lh%M');
368                    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
369                         $date_formats = array_map(create_function('$f',
370                                                         'return str_replace(\'%e\',\'%#d\',$f);'
371                                                         ),$date_formats);
372                    }
373
374                    $strReqFormat = 'INSERT INTO '.$core->prefix.'setting';
375                    $strReqFormat .= ' (setting_id,setting_ns,setting_value,setting_type,setting_label)';
376                    $strReqFormat .= ' VALUES(\'%s\',\'system\',\'%s\',\'string\',\'%s\')';
377                   
378                    $strReqSelect = 'SELECT count(1) FROM '.$core->prefix.'setting';
379                    $strReqSelect .= ' WHERE setting_id = \'%s\'';
380                    $strReqSelect .= ' AND setting_ns = \'system\'';
381                    $strReqSelect .= ' AND blog_id IS NULL';
382
383                    $rs = $core->con->select(sprintf($strReqSelect,'date_formats'));
384                    if ($rs->f(0)==0) {
385                         $strReq = sprintf($strReqFormat,'date_formats',serialize($date_formats),'Date formats examples');
386                         $core->con->execute($strReq);                     
387                    }
388                    $rs = $core->con->select(sprintf($strReqSelect,'time_formats'));
389                    if ($rs->f(0)==0) {
390                         $strReq = sprintf($strReqFormat,'time_formats',serialize($time_formats),'Time formats examples');
391                         $core->con->execute($strReq);
392                    }
393               }
394               
395               $core->setVersion('core',DC_VERSION);
396               $core->blogDefaults();
397               
398               # Drop content from session table if changes or if needed
399               if ($changes != 0 || $cleanup_sessions) {
400                    $core->con->execute('DELETE FROM '.$core->prefix.'session ');
401               }
402               
403               # Empty templates cache directory
404               try {
405                    $core->emptyTemplatesCache();
406               } catch (Exception $e) {}
407               
408               return $changes;
409          }
410          catch (Exception $e)
411          {
412               throw new Exception(__('Something went wrong with auto upgrade:').
413               ' '.$e->getMessage());
414          }
415     }
416     
417     # No upgrade?
418     return false;
419}
420?>
Note: See TracBrowser for help on using the repository browser.

Sites map