aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Updater.php46
1 files changed, 44 insertions, 2 deletions
diff --git a/application/Updater.php b/application/Updater.php
index 36eddd4f..94b63990 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -138,10 +138,10 @@ class Updater
138 public function updateMethodRenameDashTags() 138 public function updateMethodRenameDashTags()
139 { 139 {
140 $linklist = $this->linkDB->filterSearch(); 140 $linklist = $this->linkDB->filterSearch();
141 foreach ($linklist as $link) { 141 foreach ($linklist as $key => $link) {
142 $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); 142 $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']);
143 $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); 143 $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true)));
144 $this->linkDB[$link['linkdate']] = $link; 144 $this->linkDB[$key] = $link;
145 } 145 }
146 $this->linkDB->save($this->conf->get('resource.page_cache')); 146 $this->linkDB->save($this->conf->get('resource.page_cache'));
147 return true; 147 return true;
@@ -215,6 +215,48 @@ class Updater
215 } 215 }
216 return true; 216 return true;
217 } 217 }
218
219 /**
220 * Update the database to use the new ID system, which replaces linkdate primary keys.
221 * Also, creation and update dates are now DateTime objects.
222 *
223 * Since this update is very sensitve (changing the whole database), the datastore will be
224 * automatically backed up into the file datastore.<datetime>.php.
225 *
226 * @return bool true if the update is successful, false otherwise.
227 */
228 public function updateMethodDatastoreIds()
229 {
230 // up to date database
231 if (isset($this->linkDB[0])) {
232 return true;
233 }
234
235 $save = $this->conf->get('resource.data_dir') .'/datastore.'. date('YmdHis') .'.php';
236 copy($this->conf->get('resource.datastore'), $save);
237
238 $links = array();
239 foreach ($this->linkDB as $offset => $value) {
240 $links[] = $value;
241 unset($this->linkDB[$offset]);
242 }
243 $links = array_reverse($links);
244 $cpt = 0;
245 foreach ($links as $l) {
246 $l['created'] = DateTime::createFromFormat('Ymd_His', $l['linkdate']);
247 if (! empty($l['updated'])) {
248 $l['updated'] = DateTime::createFromFormat('Ymd_His', $l['updated']);
249 }
250 unset($l['linkdate']);
251 $l['id'] = $cpt;
252 $this->linkDB[$cpt++] = $l;
253 }
254
255 $this->linkDB->save($this->conf->get('resource.page_cache'));
256 $this->linkDB->reorder();
257
258 return true;
259 }
218} 260}
219 261
220/** 262/**