Dotclear

source: plugins/blocNotes/_install.php @ 1925

Revision 1925, 3.8 KB checked in by Moe, 14 years ago (diff)

Bloc-Notes 1.0.4:

  • fixed bug with PostgreSQL (closes #230)
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Bloc-Notes.
5# Copyright 2008,2009 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# encode settings to preserve new lines when editing about:config
41if (version_compare($i_version,'1.0.2','<'))
42{
43     # per-blog setting
44     $rs = $core->con->select('SELECT setting_value, setting_id, blog_id '.
45     'FROM '.$core->prefix.'setting '.
46     'WHERE setting_ns = \'blocnotes\' '.
47     'AND (setting_id = \'blocNotes_text\');');
48     
49     while($rs->fetch())
50     {
51          $cur = $core->con->openCursor($core->prefix.'setting');
52          $cur->setting_value = base64_encode($rs->setting_value);
53          $cur->update('WHERE setting_ns = \'blocnotes\' '.
54               'AND setting_id = \''.$rs->setting_id.'\''.
55               'AND blog_id = \''.$rs->blog_id.'\';');
56     }
57     
58     # users setting (global)
59     $rs = $core->con->select('SELECT setting_value, setting_id, blog_id '.
60     'FROM '.$core->prefix.'setting '.
61     'WHERE setting_ns = \'blocnotes\' '.
62     'AND (setting_id LIKE \'blocNotes_text_%\');');
63     
64     while($rs->fetch())
65     {
66          $cur = $core->con->openCursor($core->prefix.'setting');
67          $cur->setting_value = base64_encode($rs->setting_value);
68          $cur->update('WHERE setting_ns = \'blocnotes\' '.
69               'AND setting_id = \''.$rs->setting_id.'\';');
70     }
71}
72
73if (version_compare($i_version,'1.0.4','<'))
74{
75     # rename blocNotes field to bloc_notes (fix problem with PostgreSQL)
76     if ($core->con->driver() == 'pgsql')
77     {
78          $core->con->execute('ALTER TABLE '.$core->prefix.'user '.
79               'RENAME COLUMN blocNotes TO bloc_notes;');
80     }
81     else
82     {
83          $core->con->execute('ALTER TABLE '.$core->prefix.'user '.
84               'CHANGE blocNotes bloc_notes TEXT;');
85     }
86}
87
88# table
89$s = new dbStruct($core->con,$core->prefix);
90 
91# add bloc_notes column to (dc_)user
92$s->user
93     ->bloc_notes('text',0,true,null)
94;
95
96$si = new dbStruct($core->con,$core->prefix);
97$changes = $si->synchronize($s);
98
99# store users setting in (dc_)user
100if (version_compare($i_version,'1.0.3','<'))
101{
102     # users setting (global)
103     $rs = $core->con->select('SELECT setting_value, setting_id '.
104     'FROM '.$core->prefix.'setting '.
105     'WHERE setting_ns = \'blocnotes\' '.
106     'AND (setting_id LIKE \'blocNotes_text_%\');');
107     
108     while($rs->fetch())
109     {
110          $user_id = str_replace('blocNotes_text_','',$rs->setting_id);
111         
112          $cur = $core->con->openCursor($core->prefix.'user');
113          $cur->blocNotes = base64_decode($rs->setting_value);
114          $cur->update('WHERE user_id = \''.$user_id.'\';');
115     }
116     
117     # delete old settings
118     $core->con->execute('DELETE FROM '.$core->prefix.'setting '.
119          'WHERE setting_ns = \'blocnotes\' '.
120          'AND (setting_id LIKE \'blocNotes_text_%\');');
121}
122
123# La procédure d'installation commence vraiment là
124$core->setVersion('blocNotes',$m_version);
125
126return true;
127?>
Note: See TracBrowser for help on using the repository browser.

Sites map