public function deleteModule(ModuleDeleteEvent $event) { if ($event->getModuleId()) { ModuleHookQuery::create()->filterByModuleId($event->getModuleId())->delete(); } return $event; }
public function delete(ModuleDeleteEvent $event) { if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) { $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); $con->beginTransaction(); try { if (null === $module->getFullNamespace()) { throw new \LogicException(Translator::getInstance()->trans('Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?', array('%name%' => $module->getCode()))); } try { $instance = $module->createInstance(); $instance->setContainer($this->container); $path = $module->getAbsoluteBaseDir(); $instance->destroy($con, $event->getDeleteData()); $fs = new Filesystem(); $fs->remove($path); } catch (\ReflectionException $ex) { // Happens probably because the module directory has been deleted. // Log a warning, and delete the database entry. Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Failed to create instance of module "%name%" when trying to delete module. Module directory has probably been deleted', array('%name%' => $module->getCode()))); } $module->delete($con); $con->commit(); $event->setModule($module); $this->cacheClear($event->getDispatcher()); } catch (\Exception $e) { $con->rollBack(); throw $e; } } }
public function delete(ModuleDeleteEvent $event) { $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME); $con->beginTransaction(); if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId(), $con))) { try { if (null === $module->getFullNamespace()) { throw new \LogicException(Translator::getInstance()->trans('Cannot instantiate module "%name%": the namespace is null. Maybe the model is not loaded ?', ['%name%' => $module->getCode()])); } // If the module is referenced by an order, display a meaningful error // instead of 'delete cannot delete' caused by a constraint violation. // FIXME: we hav to find a way to delete modules used by order. if (OrderQuery::create()->filterByDeliveryModuleId($module->getId())->count() > 0 || OrderQuery::create()->filterByPaymentModuleId($module->getId())->count() > 0) { throw new \LogicException(Translator::getInstance()->trans('The module "%name%" is currently in use by at least one order, and can\'t be deleted.', ['%name%' => $module->getCode()])); } try { // First, try to create an instance $instance = $module->createInstance(); // Then, if module is activated, check if we can deactivate it if ($module->getActivate()) { // check for modules that depend of this one $this->checkDeactivation($module); } $instance->setContainer($this->container); $path = $module->getAbsoluteBaseDir(); $instance->destroy($con, $event->getDeleteData()); $fs = new Filesystem(); $fs->remove($path); } catch (\ReflectionException $ex) { // Happens probably because the module directory has been deleted. // Log a warning, and delete the database entry. Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Failed to create instance of module "%name%" when trying to delete module. Module directory has probably been deleted', ['%name%' => $module->getCode()])); } catch (FileNotFoundException $fnfe) { // The module directory has been deleted. // Log a warning, and delete the database entry. Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Module "%name%" directory was not found', ['%name%' => $module->getCode()])); } $module->delete($con); $con->commit(); $event->setModule($module); $this->cacheClear($event->getDispatcher()); } catch (\Exception $e) { $con->rollBack(); throw $e; } } }