/** * sync * * @param SiteInterface $site * @throws \InvalidArgumentException */ public function sync(SiteInterface $site = null) { if ($site->getAliasOf()) { return $this; } $finder = new Finder(); if (is_null($site)) { $site = $this->getSiteManager()->getCurrentAdminSite(); if (!$site) { throw new \InvalidArgumentException('GalleryManager:sync was called with no site and the default site could not be loaded'); } } $finder->files()->name('/\\.(' . implode('|', $this->options['allowed_file_types']) . ')/')->exclude(array('cache', 'bundles', 'logs'))->in($site->getWebDir()); foreach ($finder as $file) { $filePath = str_replace($site->getWebDir(), '', $file->getRealPath()); if (empty($filePath)) { $filePath = '/'; } $galleryItem = $this->getEntityManager()->getRepository('SplicedCmsBundle:GalleryItem')->findOneBy(array('site' => $site->getId(), 'filePath' => $filePath, 'fileName' => $file->getFilename())); $image = $this->imagine->open($file->getRealPath()); $imageDimensions = $image->getSize(); if (!$galleryItem) { $galleryItem = new GalleryItem(); $galleryItem->setSite($site)->setFileName($file->getFilename())->setFilePath($filePath)->setFileType($file->getExtension()); } $galleryItem->setImageHeight($imageDimensions->getHeight())->setImageWidth($imageDimensions->getWidth()); if ($galleryItem->getId()) { $this->update($galleryItem); } else { $this->save($galleryItem); } } return $this; }
public function rebuildConfiguration(SiteInterface $site) { if ($site->getAliasOf()) { return $this; } foreach (array('vhost.apache.conf.twig', 'vhost.nginx.conf.twig', 'php.ini.twig', 'php-fpm.conf.twig') as $file) { $compiledFileName = preg_replace('/\\.twig$/', '', $file); $compiledFile = $this->getTemplateEngine()->render('SplicedCmsBundle:Config/site:' . $file, array('site' => $site)); file_put_contents($site->getRootDir() . '/conf/' . $compiledFileName, $compiledFile); } }