Exemplo n.º 1
0
 /**
  * Copies website to a location.
  *
  * @param Website $orgWebsite
  *
  * @return Website
  */
 public function copyWebsite(Website $orgWebsite)
 {
     $orgRoot = $orgWebsite->getRoot();
     $orgOptions = $orgWebsite->getOptions();
     $websitePages = $this->websitePageRepository->children($orgRoot);
     array_unshift($websitePages, $orgRoot);
     $newWebsitePagesMap = array();
     $newWebsite = new Website($orgWebsite->isTest());
     foreach ($websitePages as $websitePage) {
         $newWebsitePage = new WebsitePage();
         $newWebsitePage->setWebsite($newWebsite);
         $newWebsitePage->importFromArray($websitePage->exportToArray());
         if ($websitePage->isRoot()) {
             $newWebsite->setRoot($newWebsitePage);
             $this->om->persist($newWebsite);
             //$this->websitePageRepository->persistAsFirstChild($newWebsitePage);
         } else {
             $newWebsitePageParent = $newWebsitePagesMap[$websitePage->getParent()->getId()];
             $newWebsitePage->setParent($newWebsitePageParent);
             $this->websitePageRepository->persistAsLastChildOf($newWebsitePage, $newWebsitePageParent);
         }
         if ($websitePage->getIsHomepage()) {
             $newWebsite->setHomePage($newWebsitePage);
         }
         $newWebsitePagesMap[$websitePage->getId()] = $newWebsitePage;
     }
     $this->om->flush();
     $newWebsite->getOptions()->importFromArray($this->webDir, $orgOptions->exportToArray($this->webDir), $this->webDir . DIRECTORY_SEPARATOR . $orgOptions->getUploadDir());
     return $newWebsite;
 }