1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class PimPluginSetupUninstall extends PimPluginSetup {
26:
27:
28:
29:
30: private $_PluginFoldername;
31:
32:
33:
34: protected $_PimPluginCollection;
35:
36:
37: protected $_PimPluginRelationsCollection;
38:
39:
40: protected $_ApiAreaCollection;
41:
42:
43: protected $_ApiActionCollection;
44:
45:
46: protected $_ApiFileCollection;
47:
48:
49: protected $_ApiFrameFileCollection;
50:
51:
52: protected $_ApiNavMainCollection;
53:
54:
55: protected $_ApiNavSubCollection;
56:
57:
58: protected $_ApiTypeCollection;
59:
60:
61: 62: 63: 64: 65: 66: 67:
68: public function setPluginFoldername($foldername) {
69: return $this->_PluginFoldername = cSecurity::escapeString($foldername);
70: }
71:
72: 73: 74: 75: 76: 77:
78: private function _setPimPluginCollection() {
79: return $this->_PimPluginCollection = new PimPluginCollection();
80: }
81:
82: 83: 84: 85: 86: 87:
88: private function _setPimPluginRelationsCollection() {
89: return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
90: }
91:
92: 93: 94: 95: 96: 97:
98: private function _setApiAreaCollection() {
99: return $this->_ApiAreaCollection = new cApiAreaCollection();
100: }
101:
102: 103: 104: 105: 106: 107:
108: private function _setApiActionCollection() {
109: return $this->_ApiActionCollection = new cApiActionCollection();
110: }
111:
112: 113: 114: 115: 116: 117:
118: private function _setApiFileCollection() {
119: return $this->_ApiFileCollection = new cApiFileCollection();
120: }
121:
122: 123: 124: 125: 126: 127:
128: private function _setApiFrameFileCollection() {
129: return $this->_ApiFrameFileCollection = new cApiFrameFileCollection();
130: }
131:
132: 133: 134: 135: 136: 137:
138: private function _setApiNavMainCollection() {
139: return $this->_ApiNavMainCollection = new cApiNavMainCollection();
140: }
141:
142: 143: 144: 145: 146: 147:
148: private function _setApiNavSubCollection() {
149: return $this->_ApiNavSubCollection = new cApiNavSubCollection();
150: }
151:
152: 153: 154: 155: 156: 157:
158: private function _setApiTypeCollection() {
159: return $this->_ApiTypeCollection = new cApiTypeCollection();
160: }
161:
162: 163: 164: 165: 166:
167: protected function _getPluginFoldername() {
168: return $this->_PluginFoldername;
169: }
170:
171:
172: 173: 174: 175: 176:
177: public function __construct() {
178:
179:
180:
181: $this->_setPimPluginCollection();
182: $this->_setPimPluginRelationsCollection();
183:
184:
185: $this->_setApiAreaCollection();
186: $this->_setApiActionCollection();
187: $this->_setApiFileCollection();
188: $this->_setApiFrameFileCollection();
189: $this->_setApiNavMainCollection();
190: $this->_setApiNavSubCollection();
191: $this->_setApiTypeCollection();
192: }
193:
194: 195: 196: 197: 198: 199: 200:
201: public function uninstall($sql = true) {
202: $cfg = cRegistry::getConfig();
203:
204:
205: $this->_PimPluginRelationsCollection->setWhere('idplugin', parent::_getPluginId());
206: $this->_PimPluginRelationsCollection->query();
207:
208: $relations = array();
209:
210: while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
211:
212: $index = $relation->get('type');
213:
214:
215: $value = $relation->get('iditem');
216: $relations[$index][] = $value;
217: }
218:
219:
220: if (!empty($relations['area'])) {
221: $this->_ApiActionCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
222: $this->_ApiFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
223: $this->_ApiFrameFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
224: $this->_ApiNavSubCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
225: $this->_ApiAreaCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
226: }
227:
228:
229: if (!empty($relations['navm'])) {
230: $this->_ApiNavMainCollection->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
231: }
232:
233:
234: if (!empty($relations['ctype'])) {
235: $this->_ApiTypeCollection->deleteByWhereClause("idtype IN('" . join("', '", $relations['ctype']) . "')");
236: }
237:
238:
239: $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
240: $this->_PimPluginCollection->query();
241: $pimPluginSql = $this->_PimPluginCollection->next();
242:
243:
244: $this->setPluginFoldername($pimPluginSql->get('folder'));
245:
246:
247:
248: if ($sql == true && PimPluginSetup::_getUpdateSqlFileExist() == false) {
249: $this->_uninstallDeleteSpecificSql();
250: }
251:
252:
253: $pluginname = $pimPluginSql->get('name');
254:
255:
256: $this->_PimPluginRelationsCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
257: $this->_PimPluginCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
258:
259:
260: if (parent::$_GuiPage instanceof cGuiPage && parent::getMode() == 3) {
261: parent::info(i18n('The plugin', 'pim') . ' <strong>' . $pluginname . '</strong> ' . i18n('has been successfully uninstalled. To apply the changes please login into backend again.', 'pim'));
262: }
263: }
264:
265: 266: 267: 268: 269:
270: protected function _uninstallDeleteSpecificSql() {
271: $cfg = cRegistry::getConfig();
272: $db = cRegistry::getDb();
273:
274: $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_uninstall.sql';
275:
276: if (!cFileHandler::exists($tempSqlFilename)) {
277: return;
278: }
279:
280: $tempSqlContent = cFileHandler::read($tempSqlFilename);
281: $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
282: $tempSqlContent = explode("\n", $tempSqlContent);
283: $tempSqlLines = count($tempSqlContent);
284:
285: $pattern = '/^(DELETE FROM|DROP TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
286:
287: for ($i = 0; $i < $tempSqlLines; $i++) {
288: if (preg_match($pattern, $tempSqlContent[$i])) {
289: $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
290: $db->query($tempSqlContent[$i]);
291: }
292: }
293: }
294:
295: 296: 297: 298: 299: 300: 301:
302: public function uninstallDir() {
303: $cfg = cRegistry::getConfig();
304:
305:
306: $folderpath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername();
307: cFileHandler::recursiveRmdir($folderpath);
308:
309: if (parent::$_GuiPage instanceof cGuiPage) {
310:
311:
312: if (!cFileHandler::exists($folderpath)) {
313: parent::info(i18n('The pluginfolder', 'pim') . ' <strong>' . $this->_getPluginFoldername() . '</strong> ' . i18n('has been successfully uninstalled.', 'pim'));
314: } else if (cFileHandler::exists($folderpath)) {
315: parent::error(i18n('The pluginfolder', 'pim') . ' <strong>' . $this->_getPluginFoldername() . '</strong> ' . i18n('could not be uninstalled.', 'pim'));
316: }
317: }
318: }
319:
320: }
321: ?>