]> git.agnieray.net Git - galette.git/blob - galette/install/scripts/upgrade-to-0.8.php
8e2b4d32efa5fe0335686e16b9f735296b9955e4
[galette.git] / galette / install / scripts / upgrade-to-0.8.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette 0.8 upgrade script
7 *
8 * PHP version 5
9 *
10 * Copyright © 2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.eu).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Upgrades
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.eu
35 * @since Available since 0.8 - 2014-01-04
36 */
37
38 namespace Galette\Updates;
39
40 use \Analog\Analog;
41 use Galette\Updater\AbstractUpdater;
42
43 /**
44 * Galette 0.8 upgrade script
45 *
46 * @category Upgrades
47 * @name Install
48 * @package Galette
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2014 The Galette Team
51 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
52 * @link http://galette.eu
53 * @since Available since 0.8 - 2014-01-04
54 */
55 class UpgradeTo08 extends AbstractUpdater
56 {
57 protected $db_version = '0.80';
58
59 /**
60 * Main constructor
61 */
62 public function __construct()
63 {
64 parent::__construct();
65 $this->setSqlScripts('0.80');
66 }
67
68 /**
69 * Update instructions
70 *
71 * @return boolean
72 */
73 protected function update()
74 {
75 $dirs = array(
76 'logs',
77 'templates_c',
78 'cache',
79 'exports',
80 'imports',
81 'photos',
82 'attachments',
83 'tempimages',
84 'files'
85 );
86
87 if ( !file_exists(GALETTE_ROOT . 'data') ) {
88 $created = @mkdir(GALETTE_ROOT . 'data');
89 if ( !$created ) {
90 $this->addError(
91 str_replace(
92 '%path',
93 GALETTE_ROOT . 'data',
94 _T("Unable to create main datadir in %path!")
95 )
96 );
97 return false;
98 }
99 }
100
101 foreach ( $dirs as $dir ) {
102 $path = GALETTE_ROOT . 'data/' . $dir;
103 if ( !file_exists($path) ) {
104 $created = @mkdir($path);
105 if ( !$created ) {
106 $this->addError(
107 str_replace(
108 '%dir',
109 $path,
110 _T("Unable to create datadir in %dir!")
111 )
112 );
113 }
114 }
115 $this->_moveDataDir($dir);
116 }
117
118 return !$this->hasErrors();
119 }
120
121 /**
122 * Move data directory
123 *
124 * @param string $dirname Directory name to move
125 *
126 * @return boolean
127 */
128 private function _moveDataDir($dirname)
129 {
130 //all directories should not be moved
131 $nomove = array(
132 'templates_c',
133 'cache',
134 'tempimages'
135 );
136
137 if ( !in_array($dirname, $nomove) ) {
138 $origdir = GALETTE_ROOT . $dirname . '/';
139 $destdir = GALETTE_DATA_PATH . $dirname . '/';
140
141 $go = false;
142 //move directory contents
143 switch ( $dirname ) {
144 case 'logs':
145 if ( GALETTE_LOGS_PATH === $destdir && file_exists($origdir) ) {
146 $go = true;
147 }
148 break;
149 case 'exports':
150 if ( GALETTE_EXPORTS_PATH === $destdir && file_exists($origdir) ) {
151 $go = true;
152 }
153 break;
154 case 'imports':
155 if ( GALETTE_IMPORTS_PATH === $destdir && file_exists($origdir) ) {
156 $go = true;
157 }
158 break;
159 case 'photos':
160 if ( GALETTE_PHOTOS_PATH === $destdir && file_exists($origdir) ) {
161 $go = true;
162 }
163 break;
164 case 'attachments':
165 if ( GALETTE_ATTACHMENTS_PATH === $destdir
166 && file_exists($origdir)
167 ) {
168 $go = true;
169 }
170 break;
171 case 'files':
172 if ( GALETTE_FILES_PATH === $destdir && file_exists($origdir) ) {
173 $go = true;
174 }
175 break;
176 }
177
178 if ( $go ) {
179 $moved = true;
180 $d = dir($origdir);
181 while (($entry = $d->read()) !== false) {
182 if ( $entry != '.' && $entry != '..' ) {
183 $moved = @rename($origdir . $entry, $destdir . $entry);
184 if ( !$moved ) {
185 $moved = false;
186 $this->addError(
187 str_replace(
188 '%file',
189 $entry,
190 _T("File %file has not been moved :-/")
191 )
192 );
193 }
194 }
195 }
196 $d->close();
197
198 if ( $moved ) {
199 $this->addReportEntry(
200 str_replace(
201 '%dir',
202 $dirname,
203 _T("Directory %dir has been moved!")
204 ),
205 self::REPORT_SUCCESS
206 );
207
208 //remove old directory?
209 //maybe it would be done by the user
210 } else {
211 $this->addError(
212 str_replace(
213 '%dir',
214 $dirname,
215 _T("Directory %dir has not been moved :(")
216 )
217 );
218 }
219 } else {
220 $this->addReportEntry(
221 str_replace(
222 '%dir',
223 $dirname,
224 _T("Directory %dir is not in its original path and will not be moved.")
225 ),
226 self::REPORT_WARNING
227 );
228 }
229 }
230 }
231 }