Exemplo n.º 1
0
 /**
  * Import
  *
  * @param \Thelia\Model\Import                        $import
  * @param \Symfony\Component\HttpFoundation\File\File $file
  * @param null|\Thelia\Model\Lang                     $language
  *
  * @return \Thelia\Core\Event\ImportEvent
  */
 public function import(Import $import, File $file, Lang $language = null)
 {
     $archiver = $this->matchArchiverByExtension($file->getFilename());
     if ($archiver !== null) {
         $file = $this->extractArchive($file, $archiver);
     }
     $serializer = $this->matchSerializerByExtension($file->getFilename());
     if ($serializer === null) {
         throw new FormValidationException(Translator::getInstance()->trans('The extension "%extension" is not allowed', ['%extension' => pathinfo($file->getFilename(), PATHINFO_EXTENSION)]));
     }
     $importHandleClass = $import->getHandleClass();
     /** @var \Thelia\ImportExport\Import\AbstractImport $instance */
     $instance = new $importHandleClass();
     // Configure handle class
     $instance->setLang($language);
     $instance->setFile($file);
     // Process import
     $event = new ImportEvent($instance, $serializer);
     $this->eventDispatcher->dispatch(TheliaEvents::IMPORT_BEGIN, $event);
     $errors = $this->processImport($event->getImport(), $event->getSerializer());
     $event->setErrors($errors);
     $this->eventDispatcher->dispatch(TheliaEvents::IMPORT_FINISHED, $event);
     $this->eventDispatcher->dispatch(TheliaEvents::IMPORT_SUCCESS, $event);
     return $event;
 }
Exemplo n.º 2
0
 protected function parseImports(SimpleXMLElement $xml)
 {
     if (false === ($imports = $xml->xpath('//config:imports/config:import'))) {
         return;
     }
     $con = Propel::getWriteConnection(ImportTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         /** @var SimpleXMLElement $import */
         foreach ($imports as $import) {
             $id = (string) $import->getAttributeAsPhp("id");
             $class = (string) $import->getAttributeAsPhp("class");
             $categoryRef = (string) $import->getAttributeAsPhp("category_id");
             if (!class_exists($class)) {
                 throw new \ErrorException("The class \"{$class}\" doesn't exist");
             }
             $category = ImportCategoryQuery::create()->findOneByRef($categoryRef);
             if (null === $category) {
                 throw new \ErrorException("The import category \"{$categoryRef}\" doesn't exist");
             }
             $importModel = ImportQuery::create()->findOneByRef($id);
             if (null === $importModel) {
                 $importModel = new Import();
                 $importModel->setRef($id);
             }
             $importModel->setImportCategory($category)->setHandleClass($class)->save($con);
             /** @var SimpleXMLElement $descriptive */
             foreach ($import->children() as $descriptive) {
                 $locale = $descriptive->getAttributeAsPhp("locale");
                 $title = null;
                 $description = null;
                 /** @var SimpleXMLElement $row */
                 foreach ($descriptive->children() as $row) {
                     switch ($row->getName()) {
                         case "title":
                             $title = (string) $row;
                             break;
                         case "description":
                             $description = (string) $row;
                             break;
                     }
                 }
                 $importModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con);
             }
         }
         $con->commit();
     } catch (\Exception $e) {
         $con->rollBack();
         Tlog::getInstance()->error($e->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Filter the query by a related \Thelia\Model\Import object
  *
  * @param \Thelia\Model\Import|ObjectCollection $import The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildImportI18nQuery The current query, for fluid interface
  */
 public function filterByImport($import, $comparison = null)
 {
     if ($import instanceof \Thelia\Model\Import) {
         return $this->addUsingAlias(ImportI18nTableMap::ID, $import->getId(), $comparison);
     } elseif ($import instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ImportI18nTableMap::ID, $import->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByImport() only accepts arguments of type \\Thelia\\Model\\Import or Collection');
     }
 }
Exemplo n.º 4
0
 /**
  * Declares an association between this object and a ChildImport object.
  *
  * @param                  ChildImport $v
  * @return                 \Thelia\Model\ImportI18n The current object (for fluent API support)
  * @throws PropelException
  */
 public function setImport(ChildImport $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aImport = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildImport object, it will not be re-added.
     if ($v !== null) {
         $v->addImportI18n($this);
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Filter the query by a related \Thelia\Model\Import object
  *
  * @param \Thelia\Model\Import|ObjectCollection $import  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildImportCategoryQuery The current query, for fluid interface
  */
 public function filterByImport($import, $comparison = null)
 {
     if ($import instanceof \Thelia\Model\Import) {
         return $this->addUsingAlias(ImportCategoryTableMap::ID, $import->getImportCategoryId(), $comparison);
     } elseif ($import instanceof ObjectCollection) {
         return $this->useImportQuery()->filterByPrimaryKeys($import->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByImport() only accepts arguments of type \\Thelia\\Model\\Import or Collection');
     }
 }
Exemplo n.º 6
0
 /**
  * Exclude object from result
  *
  * @param   ChildImport $import Object to remove from the list of results
  *
  * @return ChildImportQuery The current query, for fluid interface
  */
 public function prune($import = null)
 {
     if ($import) {
         $this->addUsingAlias(ImportTableMap::ID, $import->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }