Dotclear

source: plugins/blocNotes/_install.php @ 2195

Revision 2195, 3.9 KB checked in by Moe, 14 years ago (diff)

Bloc-Notes 1.0.5 :

  • update the database only if the plugin has already been installed
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Bloc-Notes.
5# Copyright 2008,2009,2010 Moe (http://gniark.net/)
6#
7# Bloc-Notes is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or
10# (at your option) any later version.
11#
12# Bloc-Notes is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20# Icons (*.png) are from Tango Icon theme :
21#    http://tango.freedesktop.org/Tango_Icon_Gallery
22#
23# ***** END LICENSE BLOCK *****
24
25if (!defined('DC_CONTEXT_ADMIN')) {return;}
26
27# On lit la version du plugin
28$m_version = $core->plugins->moduleInfo('blocNotes','version');
29 
30# On lit la version du plugin dans la table des versions
31$i_version = $core->getVersion('blocNotes');
32 
33# La version dans la table est supérieure ou égale à
34# celle du module, on ne fait rien puisque celui-ci
35# est installé
36if (version_compare($i_version,$m_version,'>=')) {
37     return;
38}
39
40# update the database only if the plugin has already been installed
41if ($i_version !== null)
42{
43     # encode settings to preserve new lines when editing about:config
44     if (version_compare($i_version,'1.0.2','<'))
45     {
46          # per-blog setting
47          $rs = $core->con->select('SELECT setting_value, setting_id, blog_id '.
48          'FROM '.$core->prefix.'setting '.
49          'WHERE setting_ns = \'blocnotes\' '.
50          'AND (setting_id = \'blocNotes_text\');');
51         
52          while($rs->fetch())
53          {
54               $cur = $core->con->openCursor($core->prefix.'setting');
55               $cur->setting_value = base64_encode($rs->setting_value);
56               $cur->update('WHERE setting_ns = \'blocnotes\' '.
57                    'AND setting_id = \''.$rs->setting_id.'\''.
58                    'AND blog_id = \''.$rs->blog_id.'\';');
59          }
60         
61          # users setting (global)
62          $rs = $core->con->select('SELECT setting_value, setting_id, blog_id '.
63          'FROM '.$core->prefix.'setting '.
64          'WHERE setting_ns = \'blocnotes\' '.
65          'AND (setting_id LIKE \'blocNotes_text_%\');');
66         
67          while($rs->fetch())
68          {
69               $cur = $core->con->openCursor($core->prefix.'setting');
70               $cur->setting_value = base64_encode($rs->setting_value);
71               $cur->update('WHERE setting_ns = \'blocnotes\' '.
72                    'AND setting_id = \''.$rs->setting_id.'\';');
73          }
74     }
75     
76     # store users setting in (dc_)user
77     if (version_compare($i_version,'1.0.3','<'))
78     {
79          # users setting (global)
80          $rs = $core->con->select('SELECT setting_value, setting_id '.
81          'FROM '.$core->prefix.'setting '.
82          'WHERE setting_ns = \'blocnotes\' '.
83          'AND (setting_id LIKE \'blocNotes_text_%\');');
84         
85          while($rs->fetch())
86          {
87               $user_id = str_replace('blocNotes_text_','',$rs->setting_id);
88               
89               $cur = $core->con->openCursor($core->prefix.'user');
90               $cur->blocNotes = base64_decode($rs->setting_value);
91               $cur->update('WHERE user_id = \''.$user_id.'\';');
92          }
93         
94          # delete old settings
95          $core->con->execute('DELETE FROM '.$core->prefix.'setting '.
96               'WHERE setting_ns = \'blocnotes\' '.
97               'AND (setting_id LIKE \'blocNotes_text_%\');');
98     }
99
100     if (version_compare($i_version,'1.0.4','<'))
101     {
102          # rename blocNotes field to bloc_notes (fix problem with PostgreSQL)
103          if ($core->con->driver() == 'pgsql')
104          {
105               $core->con->execute('ALTER TABLE '.$core->prefix.'user '.
106                    'RENAME COLUMN blocNotes TO bloc_notes;');
107          }
108          else
109          {
110               $core->con->execute('ALTER TABLE '.$core->prefix.'user '.
111                    'CHANGE blocNotes bloc_notes TEXT;');
112          }
113     }
114}
115
116# table
117$s = new dbStruct($core->con,$core->prefix);
118 
119# add bloc_notes column to (dc_)user
120$s->user
121     ->bloc_notes('text',0,true,null)
122;
123
124$si = new dbStruct($core->con,$core->prefix);
125$changes = $si->synchronize($s);
126
127# La procédure d'installation commence vraiment là
128$core->setVersion('blocNotes',$m_version);
129
130return true;
131?>
Note: See TracBrowser for help on using the repository browser.

Sites map