/**
  * @inheritdoc
  */
 public function importProfile(UploadedFile $file)
 {
     /** @var \Shopware_Components_Plugin_Namespace $namespace */
     $namespace = $this->snippetManager->getNamespace('backend/swag_import_export/controller');
     if (strtolower($file->getClientOriginalExtension()) !== 'json') {
         $this->fileSystem->remove($file->getPathname());
         throw new \Exception($namespace->get('swag_import_export/profile/profile_import_no_json_error'));
     }
     $content = file_get_contents($file->getPathname());
     if (empty($content)) {
         $this->fileSystem->remove($file->getPathname());
         throw new \Exception($namespace->get('swag_import_export/profile/profile_import_no_data_error'));
     }
     $profileData = (array) json_decode($content);
     if (empty($profileData['name']) || empty($profileData['type']) || empty($profileData['tree'])) {
         $this->fileSystem->remove($file->getPathname());
         throw new \Exception($namespace->get('swag_import_export/profile/profile_import_no_valid_data_error'));
     }
     try {
         $profile = new Profile();
         $profile->setName($profileData['name']);
         $profile->setType($profileData['type']);
         $profile->setTree(json_encode($profileData['tree']));
         $this->modelManager->persist($profile);
         $this->modelManager->flush($profile);
         $this->fileSystem->remove($file->getPathname());
     } catch (\Exception $e) {
         $this->fileSystem->remove($file->getPathname());
         $message = $e->getMessage();
         $msg = $namespace->get('swag_import_export/profile/profile_import_error');
         if (strpbrk('Duplicate entry', $message) !== false) {
             $msg = $namespace->get('swag_import_export/profile/profile_import_duplicate_error');
         }
         throw new \Exception($msg);
     }
 }
Example #2
0
 /**
  * Returns a snippet model instance
  *
  * @param       string $namespace
  * @return      Enlight_Components_Snippet_Namespace
  * @deprecated  4.0 - 2012/04/01
  */
 public function getSnippet($namespace = null)
 {
     return parent::getNamespace($namespace);
 }
Example #3
0
 /**
  * Test case
  */
 public function testGetNamespace()
 {
     $manager = new Enlight_Components_Snippet_Manager(array('adapter' => $this->adapter));
     $this->assertInstanceOf('Enlight_Components_Snippet_Namespace', $manager->getNamespace('test'));
 }
 private function getSnippetNamespace($namespace)
 {
     return $this->snippedManager->getNamespace($namespace);
 }