]> git.agnieray.net Git - galette.git/blob - galette/install/scripts/upgrade-to-0.8.php
Remove 'svn' lines
[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 * @link http://galette.eu
34 * @since Available since 0.8 - 2014-01-04
35 */
36
37 namespace Galette\Updates;
38
39 use \Analog\Analog;
40 use Galette\Updater\AbstractUpdater;
41
42 /**
43 * Galette 0.8 upgrade script
44 *
45 * @category Upgrades
46 * @name Install
47 * @package Galette
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2014 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.eu
52 * @since Available since 0.8 - 2014-01-04
53 */
54 class UpgradeTo08 extends AbstractUpdater
55 {
56 protected $db_version = '0.80';
57
58 /**
59 * Main constructor
60 */
61 public function __construct()
62 {
63 parent::__construct();
64 $this->setSqlScripts('0.80');
65 }
66
67 /**
68 * Update instructions
69 *
70 * @return boolean
71 */
72 protected function update()
73 {
74 $dirs = array(
75 'logs',
76 'templates_c',
77 'cache',
78 'exports',
79 'imports',
80 'photos',
81 'attachments',
82 'tempimages',
83 'files'
84 );
85
86 if (!file_exists(GALETTE_ROOT . 'data')) {
87 $created = @mkdir(GALETTE_ROOT . 'data');
88 if (!$created) {
89 $this->addError(
90 str_replace(
91 '%path',
92 GALETTE_ROOT . 'data',
93 _T("Unable to create main datadir in %path!")
94 )
95 );
96 return false;
97 }
98 }
99
100 foreach ($dirs as $dir) {
101 $path = GALETTE_ROOT . 'data/' . $dir;
102 if (!file_exists($path)) {
103 $created = @mkdir($path);
104 if (!$created) {
105 $this->addError(
106 str_replace(
107 '%dir',
108 $path,
109 _T("Unable to create datadir in %dir!")
110 )
111 );
112 }
113 }
114 $this->_moveDataDir($dir);
115 }
116
117 return !$this->hasErrors();
118 }
119
120 /**
121 * Move data directory
122 *
123 * @param string $dirname Directory name to move
124 *
125 * @return boolean
126 */
127 private function _moveDataDir($dirname)
128 {
129 //all directories should not be moved
130 $nomove = array(
131 'templates_c',
132 'cache',
133 'tempimages'
134 );
135
136 if (!in_array($dirname, $nomove)) {
137 $origdir = GALETTE_ROOT . $dirname . '/';
138 $destdir = GALETTE_DATA_PATH . $dirname . '/';
139
140 $go = false;
141 //move directory contents
142 switch ($dirname) {
143 case 'logs':
144 if (GALETTE_LOGS_PATH === $destdir && file_exists($origdir)) {
145 $go = true;
146 }
147 break;
148 case 'exports':
149 if (GALETTE_EXPORTS_PATH === $destdir && file_exists($origdir)) {
150 $go = true;
151 }
152 break;
153 case 'imports':
154 if (GALETTE_IMPORTS_PATH === $destdir && file_exists($origdir)) {
155 $go = true;
156 }
157 break;
158 case 'photos':
159 if (GALETTE_PHOTOS_PATH === $destdir && file_exists($origdir)) {
160 $go = true;
161 }
162 break;
163 case 'attachments':
164 if (GALETTE_ATTACHMENTS_PATH === $destdir
165 && file_exists($origdir)
166 ) {
167 $go = true;
168 }
169 break;
170 case 'files':
171 if (GALETTE_FILES_PATH === $destdir && file_exists($origdir)) {
172 $go = true;
173 }
174 break;
175 }
176
177 if ($go) {
178 $moved = true;
179 $d = dir($origdir);
180 while (($entry = $d->read()) !== false) {
181 if ($entry != '.' && $entry != '..') {
182 $moved = @rename($origdir . $entry, $destdir . $entry);
183 if (!$moved) {
184 $moved = false;
185 $this->addError(
186 str_replace(
187 '%file',
188 $entry,
189 _T("File %file has not been moved :-/")
190 )
191 );
192 }
193 }
194 }
195 $d->close();
196
197 if ($moved) {
198 $this->addReportEntry(
199 str_replace(
200 '%dir',
201 $dirname,
202 _T("Directory %dir has been moved!")
203 ),
204 self::REPORT_SUCCESS
205 );
206
207 //remove old directory?
208 //maybe it would be done by the user
209 } else {
210 $this->addError(
211 str_replace(
212 '%dir',
213 $dirname,
214 _T("Directory %dir has not been moved :(")
215 )
216 );
217 }
218 } else {
219 $this->addReportEntry(
220 str_replace(
221 '%dir',
222 $dirname,
223 _T("Directory %dir is not in its original path and will not be moved.")
224 ),
225 self::REPORT_WARNING
226 );
227 }
228 }
229 }
230 }