end updating module list
This commit is contained in:
@@ -22,7 +22,15 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Module;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Thelia\Model\Map\ModuleTableMap;
|
||||
use Thelia\Model\Module;
|
||||
use Thelia\Model\ModuleI18n;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,6 +41,7 @@ use Symfony\Component\Finder\Finder;
|
||||
class ModuleManagement
|
||||
{
|
||||
protected $baseModuleDir;
|
||||
protected $reflected;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -50,8 +59,63 @@ class ModuleManagement
|
||||
$descriptorValidator = new ModuleDescriptorValidator();
|
||||
foreach ($finder as $file) {
|
||||
$content = $descriptorValidator->getDescriptor($file->getRealPath());
|
||||
var_dump($content); exit;
|
||||
$reflected = new \ReflectionClass((string)$content->fullnamespace);
|
||||
$code = basename(dirname($reflected->getFileName()));
|
||||
if(null === ModuleQuery::create()->filterByCode($code)->findOne()) {
|
||||
$module = new Module();
|
||||
$con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
$module
|
||||
->setCode($code)
|
||||
->setFullNamespace((string)$content->fullnamespace)
|
||||
->setType($this->getModuleType($reflected))
|
||||
->setActivate(0)
|
||||
->save($con);
|
||||
|
||||
$this->saveDescription($module, $content, $con);
|
||||
|
||||
$con->commit();
|
||||
} catch(PropelException $e) {
|
||||
$con->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function saveDescription(Module $module,\SimpleXMLElement $content, ConnectionInterface $con)
|
||||
{
|
||||
|
||||
foreach($content->descriptive as $description)
|
||||
{
|
||||
$locale = $description->attributes()->locale;
|
||||
|
||||
$moduleI18n = new ModuleI18n();
|
||||
|
||||
$moduleI18n
|
||||
->setLocale($locale)
|
||||
->setModule($module)
|
||||
->setTitle($description->title)
|
||||
->setDescription(isset($description->description)?$description->description:null)
|
||||
->setPostscriptum(isset($description->postscriptum)?$description->postscriptum:null)
|
||||
->setChapo(isset($description->subtitle)?$description->subtitle:null)
|
||||
->save($con);
|
||||
}
|
||||
}
|
||||
|
||||
private function getModuleType(\ReflectionClass $reflected)
|
||||
{
|
||||
if($reflected->implementsInterface('Thelia\Module\DeliveryModuleInterface')) {
|
||||
return BaseModule::DELIVERY_MODULE_TYPE;
|
||||
} else if($reflected->implementsInterface('Thelia\Module\PaymentModuleInterface')) {
|
||||
return BaseModule::PAYMENT_MODULE_TYPE;
|
||||
} else {
|
||||
return BaseModule::CLASSIC_MODULE_TYPE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user