public function save(Layout $layout)
    {
        $archiveDir = $this->getUploadDir().'/archives';
        $templateDir = $this->getUploadDir().'/templates';
        $tmpDir = $this->getUploadDir().'/tmp/'.time();

        // Copy the archive to the archive directory
        $file = $layout->getFile()->move(
            $archiveDir,
            $layout->getFile()->getClientOriginalName()
        );

        // Extract the archive
        $zip = new \ZipArchive();
        $zip->open($archiveDir.'/'.$layout->getFile()->getClientOriginalName());
        $zip->extractTo($tmpDir);
        $zip->close();

        $config = $this->readConfiguration($tmpDir);

        $this->om->beginTransaction();
        try {
            $id = $this->getUniqueId($layout);

            $this->saveInDb(
                $config['label'],
                'uploads/' . $id . '/' . $config['templateName'],
                '/bundles/canaltpmtt/img/uploads/' . $id . '/' . $config['previewFileName'],
                $config['orientation'],
                isset($config['pageSize']) ? $config['pageSize'] : Layout::PAGE_SIZE_A4
            );

            // Move the assets
            $this->moveFiles(array('*.png', '*.jpg'), $tmpDir, $templateDir . '/img/' . $id);
            $this->moveFiles('*.twig', $tmpDir, $templateDir . '/twig/' . $id);
            $this->moveFiles('*.css', $tmpDir, $templateDir . '/css/' . $id, false);

            // If the layout has a fonts directory, we copy this directory to the css one.
            if ($fontsDirs = $this->getDirectories($tmpDir, 'fonts')) {
                $this->filesystem->remove($templateDir . '/css/' . $id . '/fonts');
                $this->filesystem->rename(current($fontsDirs), $templateDir . '/css/' . $id . '/fonts', true);
            }

            // Remove the tmp directory
            $this->filesystem->remove($tmpDir);
            $this->om->commit();
        } catch (\Exception $e) {
            $this->om->rollback();
            throw $e;
        }
    }
public function save(Layout $layout)
    {
        $archiveDir = $this->getUploadDir().'/archives';
        $templateDir = $this->getUploadDir().'/templates';
        $tmpDir = $this->getUploadDir().'/tmp/'.time();

        // Copy the archive to the archive directory
        $file = $layout->getFile()->move(
            $archiveDir,
            $layout->getFile()->getClientOriginalName()
        );

        // Extract the archive
        $zip = new \ZipArchive();
        $zip->open($archiveDir.'/'.$layout->getFile()->getClientOriginalName());
        $zip->extractTo($tmpDir);
        $zip->close();

        $config = $this->readConfiguration($tmpDir);

        $this->om->beginTransaction();
        try {
            $id = $this->getUniqueId($layout);

            $this->saveInDb(
                $config['label'],
                'uploads/' . $id . '/' . $config['templateName'],
                '/bundles/canaltpmtt/img/uploads/' . $id . '/' . $config['previewFileName'],
                $config['orientation'],
                isset($config['pageSize']) ? $config['pageSize'] : Layout::PAGE_SIZE_A4
            );

            // Move the assets
            $this->moveFiles(array('*.png', '*.jpg'), $tmpDir, $templateDir . '/img/' . $id);
            $this->moveFiles('*.twig', $tmpDir, $templateDir . '/twig/' . $id);
            $this->moveFiles('*.css', $tmpDir, $templateDir . '/css/' . $id, false);

            // If the layout has a fonts directory, we copy this directory to the css one.
            if ($fontsDirs = $this->getDirectories($tmpDir, 'fonts')) {
                $this->filesystem->remove($templateDir . '/css/' . $id . '/fonts');
                $this->filesystem->rename(current($fontsDirs), $templateDir . '/css/' . $id . '/fonts', true);
            }

            // Remove the tmp directory
            $this->filesystem->remove($tmpDir);
            $this->om->commit();
        } catch (\Exception $e) {
            $this->om->rollback();
            throw $e;
        }
    }
public function save ( Layout $ layout ) { $ archiveDir = $ this -> getUploadDir ( ) . '/archives' ; $ templateDir = $ this -> getUploadDir ( ) . '/templates' ; $ tmpDir = $ this -> getUploadDir ( ) . '/tmp/' . time ( ) ; // Copy the archive to the archive directory $ file = $ layout -> getFile ( ) -> move ( $ archiveDir , $ layout -> getFile ( ) -> getClientOriginalName ( ) ) ; // Extract the archive $ zip = new \ ZipArchive ( ) ; $ zip -> open ( $ archiveDir . '/' . $ layout -> getFile ( ) -> getClientOriginalName ( ) ) ; $ zip -> extractTo ( $ tmpDir ) ; $ zip -> close ( ) ; $ config = $ this -> readConfiguration ( $ tmpDir ) ; $ this -> om -> beginTransaction ( ) ; try { $ id = $ this -> getUniqueId ( $ layout ) ; $ this -> saveInDb ( $ config [ 'label' ] , 'uploads/' . $ id . '/' . $ config [ 'templateName' ] , '/bundles/canaltpmtt/img/uploads/' . $ id . '/' . $ config [ 'previewFileName' ] , $ config [ 'orientation' ] , isset ( $ config [ 'pageSize' ] ) ? $ config [ 'pageSize' ] : Layout :: PAGE_SIZE_A4 ) ; // Move the assets $ this -> moveFiles ( array ( '*.png' , '*.jpg' ) , $ tmpDir , $ templateDir . '/img/' . $ id ) ; $ this -> moveFiles ( '*.twig' , $ tmpDir , $ templateDir . '/twig/' . $ id ) ; $ this -> moveFiles ( '*.css' , $ tmpDir , $ templateDir . '/css/' . $ id , false ) ; // If the layout has a fonts directory, we copy this directory to the css one. if ( $ fontsDirs = $ this -> getDirectories ( $ tmpDir , 'fonts' ) ) { $ this -> filesystem -> remove ( $ templateDir . '/css/' . $ id . '/fonts' ) ; $ this -> filesystem -> rename ( current ( $ fontsDirs ) , $ templateDir . '/css/' . $ id . '/fonts' , true ) ; } // Remove the tmp directory $ this -> filesystem -> remove ( $ tmpDir ) ; $ this -> om -> commit ( ) ; } catch ( \ Exception $ e ) { $ this -> om -> rollback ( ) ; throw $ e ; } }
Persist template and move zip archive's elements.

@param Layout $layout
Persist template and move zip archive s elements .