forked from ZenMagick/ZenMagick
/
AdminPrefsPatch.php
101 lines (89 loc) · 2.82 KB
/
AdminPrefsPatch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
* ZenMagick - Smart e-commerce
* Copyright (C) 2006-2011 zenmagick.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
?>
<?php
namespace zenmagick\apps\store\admin\installation\patches\sql;
use zenmagick\base\Runtime;
use zenmagick\apps\store\admin\installation\patches\SQLPatch;
/**
* Patch to create the admin prefs tables.
*
* @author DerManoMann <mano@zenmagick.org>
*/
class AdminPrefsPatch extends SQLPatch {
var $sqlFiles_ = array(
"/shared/etc/sql/mysql/admin_prefs_install.sql"
);
var $sqlUndoFiles_ = array(
"/shared/etc/sql/mysql/admin_prefs_uninstall.sql"
);
/**
* Create new instance.
*/
public function __construct() {
parent::__construct('sqlAdminPrefs');
}
/**
* Checks if this patch can still be applied.
*
* @return boolean <code>true</code> if this patch can still be applied.
*/
function isOpen() {
$meta = \ZMRuntime::getDatabase()->getMetaData();
return !in_array(DB_PREFIX.'admin_prefs', $meta['tables']);
}
/**
* Execute this patch.
*
* @param boolean force If set to <code>true</code> it will force patching even if
* disabled as per settings.
* @return boolean <code>true</code> if patching was successful, <code>false</code> if not.
*/
function patch($force=false) {
$baseDir = Runtime::getInstallationPath();
// do only interactive
if ($force) {
$status = true;
foreach ($this->sqlFiles_ as $file) {
$sql = file($baseDir.$file);
$status |= $this->_runSQL($sql);
}
return $status;
}
return true;
}
/**
* Revert the patch.
*
* @return boolean <code>true</code> if patching was successful, <code>false</code> if not.
*/
function undo() {
if ($this->isOpen()) {
return true;
}
$baseDir = Runtime::getInstallationPath();
$status = true;
foreach ($this->sqlUndoFiles_ as $file) {
$sql = file($baseDir.$file);
$status |= $this->_runSQL($sql);
}
return $status;
}
}