1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2010 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 ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | function 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) |
---|
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 | |
---|
188 | $core->setVersion('core',DC_VERSION); |
---|
189 | $core->blogDefaults(); |
---|
190 | |
---|
191 | # Drop content from session table |
---|
192 | $core->con->execute('DELETE FROM '.$core->prefix.'session '); |
---|
193 | |
---|
194 | # Empty templates cache directory |
---|
195 | try { |
---|
196 | $core->emptyTemplatesCache(); |
---|
197 | } catch (Exception $e) {} |
---|
198 | |
---|
199 | return $changes; |
---|
200 | } |
---|
201 | catch (Exception $e) |
---|
202 | { |
---|
203 | throw new Exception(__('Something went wrong with auto upgrade:'). |
---|
204 | ' '.$e->getMessage()); |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | # No upgrade? |
---|
209 | return false; |
---|
210 | } |
---|
211 | ?> |
---|