Exemplo n.º 1
0
 /**
  * Registers a plugin in the collection.
  * If $removeData is set to false the plugin data will not be removed.
  *
  * @param Shopware_Components_Plugin_Bootstrap $bootstrap
  * @param bool $removeData
  * @return bool
  * @throws Exception
  */
 public function uninstallPlugin(Shopware_Components_Plugin_Bootstrap $bootstrap, $removeData = true)
 {
     /** @var \Shopware\Components\Model\ModelManager $em */
     $em = $this->Application()->Models();
     /** @var \Enlight_Components_Db_Adapter_Pdo_Mysql $db */
     $db = $this->Application()->Db();
     $id = $this->getPluginId($bootstrap->getName());
     $plugin = $em->find('Shopware\\Models\\Plugin\\Plugin', $id);
     $this->Application()->Events()->notify('Shopware_Plugin_PreUninstall', array('subject' => $this, 'plugin' => $bootstrap, 'removeData' => $removeData));
     $result = $bootstrap->disable();
     $capabilities = $bootstrap->getCapabilities();
     $capabilities['secureUninstall'] = !empty($capabilities['secureUninstall']);
     $success = is_bool($result) ? $result : !empty($result['success']);
     if (!$success) {
         return $result;
     }
     $this->Application()->Events()->notify('Shopware_Plugin_PostUninstall', array('subject' => $this, 'plugin' => $bootstrap, 'removeData' => $removeData));
     if ($removeData) {
         $result = $bootstrap->uninstall();
     } elseif ($capabilities['secureUninstall']) {
         $result = $bootstrap->secureUninstall();
     } else {
         throw new \Exception('Plugin does not support secure uninstall.');
     }
     $this->Application()->Events()->notify('Shopware_Plugin_PostUninstall', array('subject' => $this, 'plugin' => $bootstrap, 'removeData' => $removeData));
     $success = is_bool($result) ? $result : !empty($result['success']);
     if (!$success) {
         return $result;
     }
     $plugin->setInstalled(null);
     $plugin->setActive(false);
     $em->flush($plugin);
     // Remove event subscribers
     $sql = 'DELETE FROM `s_core_subscribes` WHERE `pluginID`=?';
     $db->query($sql, array($id));
     // Remove crontab-entries
     $sql = 'DELETE FROM `s_crontab` WHERE `pluginID`=?';
     $db->query($sql, array($id));
     // Remove form
     $this->removeForm($bootstrap, $removeData);
     // Remove snippets
     if ($capabilities['secureUninstall']) {
         $bootstrap->removeSnippets($removeData);
     } else {
         $bootstrap->removeSnippets(true);
     }
     // Remove menu-entry
     $query = 'DELETE FROM Shopware\\Models\\Menu\\Menu m WHERE m.pluginId = ?0';
     $query = $em->createQuery($query);
     $query->execute(array($id));
     // Remove templates
     $query = 'DELETE FROM Shopware\\Models\\Shop\\Template t WHERE t.pluginId = ?0';
     $query = $em->createQuery($query);
     $query->execute(array($id));
     // Remove emotion-components
     $sql = "DELETE s_emotion_element_value, s_emotion_element\n                FROM s_emotion_element_value\n                RIGHT JOIN s_emotion_element\n                    ON s_emotion_element.id = s_emotion_element_value.elementID\n                INNER JOIN s_library_component\n                    ON s_library_component.id = s_emotion_element.componentID\n                    AND s_library_component.pluginID = :pluginId";
     $db->query($sql, array(':pluginId' => $id));
     $sql = "DELETE s_library_component_field, s_library_component\n                FROM s_library_component_field\n                INNER JOIN s_library_component\n                    ON s_library_component.id = s_library_component_field.componentID\n                    AND s_library_component.pluginID = :pluginId";
     $db->query($sql, array(':pluginId' => $id));
     $this->removePluginWidgets($id);
     return $result;
 }