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