Dotclear

source: inc/dbschema/upgrade.php @ 1581:9b4081b29202

Revision 1581:9b4081b29202, 12.2 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Cope with new README.md rather than old README for build and update, addresses #1510

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     $version = $core->getVersion('core');
17     
18     if ($version === null) {
19          return false;
20     }
21     
22     if (version_compare($version,DC_VERSION,'<') == 1 || strpos(DC_VERSION,'dev'))
23     {
24          try
25          {
26               if ($core->con->driver() == 'sqlite') {
27                    throw new Exception(__('SQLite Database Schema cannot be upgraded.'));
28               }
29               
30               # Database upgrade
31               $_s = new dbStruct($core->con,$core->prefix);
32               require dirname(__FILE__).'/db-schema.php';
33               
34               $si = new dbStruct($core->con,$core->prefix);
35               $changes = $si->synchronize($_s);
36               
37               /* Some other upgrades
38               ------------------------------------ */
39               # Populate media_dir field (since 2.0-beta3.3)
40               if (version_compare($version,'2.0-beta3.3','<'))
41               {
42                    $strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media ';
43                    $rs_m = $core->con->select($strReq);
44                    while($rs_m->fetch()) {
45                         $cur = $core->con->openCursor($core->prefix.'media');
46                         $cur->media_dir = dirname($rs_m->media_file);
47                         $cur->update('WHERE media_id = '.(integer) $rs_m->media_id);
48                    }
49               }
50               
51               if (version_compare($version,'2.0-beta7.3','<'))
52               {
53                    # Blowup becomes default theme
54                    $strReq = 'UPDATE '.$core->prefix.'setting '.
55                              "SET setting_value = '%s' ".
56                              "WHERE setting_id = 'theme' ".
57                              "AND setting_value = '%s' ".
58                              'AND blog_id IS NOT NULL ';
59                    $core->con->execute(sprintf($strReq,'blueSilence','default'));
60                    $core->con->execute(sprintf($strReq,'default','blowup'));
61               }
62               
63               if (version_compare($version,'2.1-alpha2-r2383','<'))
64               {
65                    $schema = dbSchema::init($core->con);
66                    $schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title');
67                   
68                    # Reindex categories
69                    $rs = $core->con->select(
70                         'SELECT cat_id, cat_title, blog_id '.
71                         'FROM '.$core->prefix.'category '.
72                         'ORDER BY blog_id ASC , cat_position ASC '
73                    );
74                    $cat_blog = $rs->blog_id;
75                    $i = 2;
76                    while ($rs->fetch()) {
77                         if ($cat_blog != $rs->blog_id) {
78                              $i = 2;
79                         }
80                         $core->con->execute(
81                              'UPDATE '.$core->prefix.'category SET '
82                              .'cat_lft = '.($i++).', cat_rgt = '.($i++).' '.
83                              'WHERE cat_id = '.(integer) $rs->cat_id
84                         );
85                         $cat_blog = $rs->blog_id;
86                    }
87               }
88               
89               if (version_compare($version,'2.1.6','<='))
90               {
91                    # ie7js has been upgraded
92                    $ie7files = array (
93                         'ie7-base64.php ',
94                         'ie7-content.htc',
95                         'ie7-core.js',
96                         'ie7-css2-selectors.js',
97                         'ie7-css3-selectors.js',
98                         'ie7-css-strict.js',
99                         'ie7-dhtml.js',
100                         'ie7-dynamic-attributes.js',
101                         'ie7-fixed.js',
102                         'ie7-graphics.js',
103                         'ie7-html4.js',
104                         'ie7-ie5.js',
105                         'ie7-layout.js',
106                         'ie7-load.htc',
107                         'ie7-object.htc',
108                         'ie7-overflow.js',
109                         'ie7-quirks.js',
110                         'ie7-server.css',
111                         'ie7-standard-p.js',
112                         'ie7-xml-extras.js'
113                         );
114                    foreach ($ie7files as $f) {
115                         @unlink(DC_ROOT.'/admin/js/ie7/'.$f);
116                    }
117               }
118               
119               if (version_compare($version,'2.2-alpha1-r3043','<'))
120               {
121                    # metadata has been integrated to the core.
122                    $core->plugins->loadModules(DC_PLUGINS_ROOT);
123                    if ($core->plugins->moduleExists('metadata')) {
124                         $core->plugins->deleteModule('metadata');
125                    }
126                   
127                    # Tags template class has been renamed
128                    $sqlstr =
129                         'SELECT blog_id, setting_id, setting_value '.
130                         'FROM '.$core->prefix.'setting '.
131                         'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '.
132                         'AND setting_ns = \'widgets\';';
133                    $rs = $core->con->select($sqlstr);
134                    while ($rs->fetch()) {
135                         $widgetsettings = base64_decode($rs->setting_value);
136                         $widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings);
137                         $cur = $core->con->openCursor($core->prefix.'setting');
138                         $cur->setting_value = base64_encode($widgetsettings);
139                         $sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '.
140                         'AND blog_id ' .
141                         ($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\'');
142                         $cur->update($sqlstr);
143                    }
144               }
145
146               if (version_compare($version,'2.3','<'))
147               {
148                    # Add global favorites
149                    $init_fav = array();
150
151                    $init_fav['new_post'] = array('new_post','New entry','post.php',
152                         'images/menu/edit.png','images/menu/edit-b.png',
153                         'usage,contentadmin',null,'menu-new-post');
154                    $init_fav['posts'] = array('posts','Entries','posts.php',
155                         'images/menu/entries.png','images/menu/entries-b.png',
156                         'usage,contentadmin',null,null);
157                    $init_fav['comments'] = array('comments','Comments','comments.php',
158                         'images/menu/comments.png','images/menu/comments-b.png',
159                         'usage,contentadmin',null,null);
160                    $init_fav['prefs'] = array('prefs','My preferences','preferences.php',
161                         'images/menu/user-pref.png','images/menu/user-pref-b.png',
162                         '*',null,null);
163                    $init_fav['blog_pref'] = array('blog_pref','Blog settings','blog_pref.php',
164                         'images/menu/blog-pref.png','images/menu/blog-pref-b.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                    $init_fav['pages'] = array('pages','Pages','plugin.php?p=pages',
171                         'index.php?pf=pages/icon.png','index.php?pf=pages/icon-big.png',
172                         'contentadmin,pages',null,null);
173                    $init_fav['blogroll'] = array('blogroll','Blogroll','plugin.php?p=blogroll',
174                         'index.php?pf=blogroll/icon-small.png','index.php?pf=blogroll/icon.png',
175                         'usage,contentadmin',null,null);
176
177                    $count = 0;
178                    foreach ($init_fav as $k => $f) {
179                         $t = array('name' => $f[0],'title' => $f[1],'url' => $f[2], 'small-icon' => $f[3],
180                              'large-icon' => $f[4],'permissions' => $f[5],'id' => $f[6],'class' => $f[7]);
181                         $sqlstr = 'INSERT INTO '.$core->prefix.'pref (pref_id, user_id, pref_ws, pref_value, pref_type, pref_label) VALUES ('.
182                              '\''.sprintf("g%03s",$count).'\',NULL,\'favorites\',\''.serialize($t).'\',\'string\',NULL);';
183                         $core->con->execute($sqlstr);
184                         $count++;
185                    }
186                   
187                    # A bit of housecleaning for no longer needed files
188                    $remfiles = array (
189                         'admin/style/cat-bg.png',
190                         'admin/style/footer-bg.png',
191                         'admin/style/head-logo.png',
192                         'admin/style/tab-bg.png',
193                         'admin/style/tab-c-l.png',
194                         'admin/style/tab-c-r.png',
195                         'admin/style/tab-l-l.png',
196                         'admin/style/tab-l-r.png',
197                         'admin/style/tab-n-l.png',
198                         'admin/style/tab-n-r.png',
199                         'inc/clearbricks/_common.php',
200                         'inc/clearbricks/common/lib.crypt.php',
201                         'inc/clearbricks/common/lib.date.php',
202                         'inc/clearbricks/common/lib.files.php',
203                         'inc/clearbricks/common/lib.form.php',
204                         'inc/clearbricks/common/lib.html.php',
205                         'inc/clearbricks/common/lib.http.php',
206                         'inc/clearbricks/common/lib.l10n.php',
207                         'inc/clearbricks/common/lib.text.php',
208                         'inc/clearbricks/common/tz.dat',
209                         'inc/clearbricks/common/_main.php',
210                         'inc/clearbricks/dblayer/class.cursor.php',
211                         'inc/clearbricks/dblayer/class.mysql.php',
212                         'inc/clearbricks/dblayer/class.pgsql.php',
213                         'inc/clearbricks/dblayer/class.sqlite.php',
214                         'inc/clearbricks/dblayer/dblayer.php',
215                         'inc/clearbricks/dbschema/class.dbschema.php',
216                         'inc/clearbricks/dbschema/class.dbstruct.php',
217                         'inc/clearbricks/dbschema/class.mysql.dbschema.php',
218                         'inc/clearbricks/dbschema/class.pgsql.dbschema.php',
219                         'inc/clearbricks/dbschema/class.sqlite.dbschema.php',
220                         'inc/clearbricks/diff/lib.diff.php',
221                         'inc/clearbricks/diff/lib.unified.diff.php',
222                         'inc/clearbricks/filemanager/class.filemanager.php',
223                         'inc/clearbricks/html.filter/class.html.filter.php',
224                         'inc/clearbricks/html.validator/class.html.validator.php',
225                         'inc/clearbricks/image/class.image.meta.php',
226                         'inc/clearbricks/image/class.image.tools.php',
227                         'inc/clearbricks/mail/class.mail.php',
228                         'inc/clearbricks/mail/class.socket.mail.php',
229                         'inc/clearbricks/net/class.net.socket.php',
230                         'inc/clearbricks/net.http/class.net.http.php',
231                         'inc/clearbricks/net.http.feed/class.feed.parser.php',
232                         'inc/clearbricks/net.http.feed/class.feed.reader.php',
233                         'inc/clearbricks/net.xmlrpc/class.net.xmlrpc.php',
234                         'inc/clearbricks/pager/class.pager.php',
235                         'inc/clearbricks/rest/class.rest.php',
236                         'inc/clearbricks/session.db/class.session.db.php',
237                         'inc/clearbricks/template/class.template.php',
238                         'inc/clearbricks/text.wiki2xhtml/class.wiki2xhtml.php',
239                         'inc/clearbricks/url.handler/class.url.handler.php',
240                         'inc/clearbricks/zip/class.unzip.php',
241                         'inc/clearbricks/zip/class.zip.php',
242                         'themes/default/tpl/.htaccess',
243                         'themes/default/tpl/404.html',
244                         'themes/default/tpl/archive.html',
245                         'themes/default/tpl/archive_month.html',
246                         'themes/default/tpl/category.html',
247                         'themes/default/tpl/home.html',
248                         'themes/default/tpl/post.html',
249                         'themes/default/tpl/search.html',
250                         'themes/default/tpl/tag.html',
251                         'themes/default/tpl/tags.html',
252                         'themes/default/tpl/user_head.html',
253                         'themes/default/tpl/_flv_player.html',
254                         'themes/default/tpl/_footer.html',
255                         'themes/default/tpl/_head.html',
256                         'themes/default/tpl/_mp3_player.html',
257                         'themes/default/tpl/_top.html'
258                    );
259                    $remfolders = array (
260                         'inc/clearbricks/common',
261                         'inc/clearbricks/dblayer',
262                         'inc/clearbricks/dbschema',
263                         'inc/clearbricks/diff',
264                         'inc/clearbricks/filemanager',
265                         'inc/clearbricks/html.filter',
266                         'inc/clearbricks/html.validator',
267                         'inc/clearbricks/image',
268                         'inc/clearbricks/mail',
269                         'inc/clearbricks/net',
270                         'inc/clearbricks/net.http',
271                         'inc/clearbricks/net.http.feed',
272                         'inc/clearbricks/net.xmlrpc',
273                         'inc/clearbricks/pager',
274                         'inc/clearbricks/rest',
275                         'inc/clearbricks/session.db',
276                         'inc/clearbricks/template',
277                         'inc/clearbricks/text.wiki2xhtml',
278                         'inc/clearbricks/url.handler',
279                         'inc/clearbricks/zip',
280                         'inc/clearbricks',
281                         'themes/default/tpl'
282                    );
283                   
284                    foreach ($remfiles as $f) {
285                         @unlink(DC_ROOT.'/'.$f);
286                    }
287                    foreach ($remfolders as $f) {
288                         @rmdir(DC_ROOT.'/'.$f);
289                    }
290               }
291               
292               if (version_compare($version,'2.3.1','<'))
293               {
294                    # Remove unecessary file
295                    @unlink(DC_ROOT.'/'.'inc/libs/clearbricks/.hgignore');
296               }
297
298               if (version_compare($version,'2.4.0','<='))
299               {
300                    # setup media_exclusion
301                    $strReq = 'UPDATE '.$core->prefix.'setting '.
302                              "SET setting_value = '/\\.php\$/i' ".
303                              "WHERE setting_id = 'media_exclusion' ".
304                              "AND setting_value = '' ";
305                    $core->con->execute($strReq);
306               }
307
308               if (version_compare($version,'2.5','<='))
309               {
310                    # Try to disable daInstaller plugin if it has been installed outside the default plugins directory
311                    $path = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT);
312                    $default = path::real(dirname(__FILE__).'/../../plugins/');
313                    foreach ($path as $root)
314                    {
315                         if (!is_dir($root) || !is_readable($root)) {
316                              continue;
317                         }
318                         if (substr($root,-1) != '/') {
319                              $root .= '/';
320                         }
321                         if (($p = @dir($root)) === false) {
322                              continue;
323                         }
324                         if(path::real($root) == $default) {
325                              continue;
326                         }
327                         if (($d = @dir($root.'daInstaller')) === false) {
328                              continue;
329                         }
330                         $f = $root.'/daInstaller/_disabled';
331                         if (!file_exists($f))
332                         {
333                              @file_put_contents($f,'');
334                         }
335                    }
336               }
337
338               if (version_compare($version,'2.5.1','<='))
339               {
340                    // Flash enhanced upload no longer needed
341                    @unlink(DC_ROOT.'/'.'inc/swf/swfupload.swf');
342               }
343
344               if (version_compare($version,'2.6','<='))
345               {
346                    // README has been replaced by README.md and CONTRIBUTING.md
347                    @unlink(DC_ROOT.'/'.'README');
348               }
349               
350               $core->setVersion('core',DC_VERSION);
351               $core->blogDefaults();
352               
353               # Drop content from session table
354               $core->con->execute('DELETE FROM '.$core->prefix.'session ');
355               
356               # Empty templates cache directory
357               try {
358                    $core->emptyTemplatesCache();
359               } catch (Exception $e) {}
360               
361               return $changes;
362          }
363          catch (Exception $e)
364          {
365               throw new Exception(__('Something went wrong with auto upgrade:').
366               ' '.$e->getMessage());
367          }
368     }
369     
370     # No upgrade?
371     return false;
372}
373?>
Note: See TracBrowser for help on using the repository browser.

Sites map