예제 #1
0
 protected function parseExports(SimpleXMLElement $xml)
 {
     if (false === ($exports = $xml->xpath('//config:exports/config:export'))) {
         return;
     }
     $con = Propel::getWriteConnection(ExportTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         /** @var SimpleXMLElement $export */
         foreach ($exports as $export) {
             $id = (string) $export->getAttributeAsPhp("id");
             $class = (string) $export->getAttributeAsPhp("class");
             $categoryRef = (string) $export->getAttributeAsPhp("category_id");
             if (!class_exists($class)) {
                 throw new \ErrorException("The class \"{$class}\" doesn't exist");
             }
             $category = ExportCategoryQuery::create()->findOneByRef($categoryRef);
             if (null === $category) {
                 throw new \ErrorException("The export category \"{$categoryRef}\" doesn't exist");
             }
             $exportModel = ExportQuery::create()->findOneByRef($id);
             if (null === $exportModel) {
                 $exportModel = new Export();
                 $exportModel->setRef($id);
             }
             $exportModel->setExportCategory($category)->setHandleClass($class)->save($con);
             /** @var SimpleXMLElement $descriptive */
             foreach ($export->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;
                     }
                 }
                 $exportModel->setLocale($locale)->setTitle($title)->setDescription($description)->save($con);
             }
         }
         $con->commit();
     } catch (\Exception $e) {
         $con->rollBack();
         Tlog::getInstance()->error($e->getMessage());
     }
 }
예제 #2
0
 /**
  * Export
  *
  * @param \Thelia\Model\Export                         $export
  * @param \Thelia\Core\Serializer\SerializerInterface  $serializer
  * @param null|\Thelia\Core\Archiver\ArchiverInterface $archiver
  * @param null|\Thelia\Model\Lang                      $language
  * @param boolean                                      $includeImages
  * @param boolean                                      $includeDocuments
  * @param null|array                                   $rangeDate
  *
  * @return \Thelia\Core\Event\ExportEvent
  */
 public function export(Export $export, SerializerInterface $serializer, ArchiverInterface $archiver = null, Lang $language = null, $includeImages = false, $includeDocuments = false, $rangeDate = null)
 {
     $exportHandleClass = $export->getHandleClass();
     /** @var \Thelia\ImportExport\Export\AbstractExport $instance */
     $instance = new $exportHandleClass();
     $instance->setContainer($this->container);
     // Configure handle class
     $instance->setLang($language);
     if ($archiver !== null) {
         if ($includeImages && $instance->hasImages()) {
             $instance->setExportImages(true);
         }
         if ($includeDocuments && $instance->hasDocuments()) {
             $instance->setExportDocuments(true);
         }
     }
     if ($rangeDate['start'] && !$rangeDate['start'] instanceof \DateTime) {
         $rangeDate['start'] = \DateTime::createFromFormat('Y-m-d H:i:s', $rangeDate['start']['year'] . '-' . $rangeDate['start']['month'] . '-1 00:00:00');
     }
     if ($rangeDate['end'] && !$rangeDate['end'] instanceof \DateTime) {
         $rangeDate['end'] = \DateTime::createFromFormat('Y-m-d H:i:s', $rangeDate['end']['year'] . '-' . ($rangeDate['end']['month'] + 1) . '-0 23:59:59');
     }
     $instance->setRangeDate($rangeDate);
     // Process export
     $event = new ExportEvent($instance, $serializer, $archiver);
     $this->eventDispatcher->dispatch(TheliaEvents::EXPORT_BEGIN, $event);
     $filePath = $this->processExport($event->getExport(), $event->getSerializer());
     $event->setFilePath($filePath);
     $this->eventDispatcher->dispatch(TheliaEvents::EXPORT_FINISHED, $event);
     if ($event->getArchiver() !== null) {
         // Create archive
         $event->getArchiver()->create($filePath);
         // Add images
         if ($includeImages && $event->getExport()->hasImages()) {
             $this->processExportImages($event->getExport(), $event->getArchiver());
         }
         // Add documents
         if ($includeDocuments && $event->getExport()->hasDocuments()) {
             $this->processExportDocuments($event->getExport(), $event->getArchiver());
         }
         // Finalize archive
         $event->getArchiver()->add($filePath)->save();
         // Change returned file path
         $event->setFilePath($event->getArchiver()->getArchivePath());
     }
     $this->eventDispatcher->dispatch(TheliaEvents::EXPORT_SUCCESS, $event);
     return $event;
 }
예제 #3
0
 /**
  * Declares an association between this object and a ChildExport object.
  *
  * @param                  ChildExport $v
  * @return                 \Thelia\Model\ExportI18n The current object (for fluent API support)
  * @throws PropelException
  */
 public function setExport(ChildExport $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aExport = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildExport object, it will not be re-added.
     if ($v !== null) {
         $v->addExportI18n($this);
     }
     return $this;
 }
예제 #4
0
 /**
  * Filter the query by a related \Thelia\Model\Export object
  *
  * @param \Thelia\Model\Export|ObjectCollection $export  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildExportCategoryQuery The current query, for fluid interface
  */
 public function filterByExport($export, $comparison = null)
 {
     if ($export instanceof \Thelia\Model\Export) {
         return $this->addUsingAlias(ExportCategoryTableMap::ID, $export->getExportCategoryId(), $comparison);
     } elseif ($export instanceof ObjectCollection) {
         return $this->useExportQuery()->filterByPrimaryKeys($export->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByExport() only accepts arguments of type \\Thelia\\Model\\Export or Collection');
     }
 }
예제 #5
0
 /**
  * Exclude object from result
  *
  * @param   ChildExport $export Object to remove from the list of results
  *
  * @return ChildExportQuery The current query, for fluid interface
  */
 public function prune($export = null)
 {
     if ($export) {
         $this->addUsingAlias(ExportTableMap::ID, $export->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
예제 #6
0
 /**
  * Filter the query by a related \Thelia\Model\Export object
  *
  * @param \Thelia\Model\Export|ObjectCollection $export The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildExportI18nQuery The current query, for fluid interface
  */
 public function filterByExport($export, $comparison = null)
 {
     if ($export instanceof \Thelia\Model\Export) {
         return $this->addUsingAlias(ExportI18nTableMap::ID, $export->getId(), $comparison);
     } elseif ($export instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ExportI18nTableMap::ID, $export->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByExport() only accepts arguments of type \\Thelia\\Model\\Export or Collection');
     }
 }