Esempio n. 1
0
 public function duplicatePage($page, $nsite, $ncategory, $newUnixName = null)
 {
     if ($newUnixName == null) {
         $newUnixName = $page->getUnixName();
     }
     // check if page exists - if so, forcibly delete!!!
     $p = DB_PagePeer::instance()->selectByName($nsite->getSiteId(), $newUnixName);
     if ($p) {
         DB_PagePeer::instance()->deleteByPrimaryKey($p->getPageId());
     }
     $owner = $this->owner;
     $now = new ODate();
     // create new page object based on the existing page
     $nsource = new DB_PageSource();
     $nsource->setText($page->getSource());
     $nsource->save();
     $meta = $page->getMetadata();
     $nmeta = new DB_PageMetadata();
     $nmeta->setTitle($meta->getTitle());
     $nmeta->setUnixName($newUnixName);
     if ($owner) {
         $nmeta->setOwnerUserId($owner->getUserId());
     } else {
         $nmeta->setOwnerUserId($meta->getOwnerUserId());
     }
     $nmeta->save();
     $rev = $page->getCurrentRevision();
     $nrev = new DB_PageRevision();
     $nrev->setSiteId($nsite->getSiteId());
     $nrev->setSourceId($nsource->getSourceId());
     $nrev->setMetadataId($nmeta->getMetadataId());
     $nrev->setFlagNew(true);
     $nrev->setFlagNewSite(true);
     $nrev->setDateLastEdited($now);
     $nrev->setUserId($owner->getUserId());
     $nrev->obtainPK();
     $npage = new DB_Page();
     $npage->setSiteId($nsite->getSiteId());
     $npage->setCategoryId($ncategory->getCategoryId());
     $npage->setRevisionId($nrev->getRevisionId());
     $npage->setSourceId($nsource->getSourceId());
     $npage->setMetadataId($nmeta->getMetadataId());
     $npage->setTitle($page->getTitle());
     $npage->setUnixName($newUnixName);
     $npage->setDateLastEdited($now);
     $npage->setDateCreated($now);
     $npage->setLastEditUserId($owner->getUserId());
     $npage->setOwnerUserId($owner->getUserId());
     $npage->save();
     $nrev->setPageId($npage->getPageId());
     $nrev->save();
     $ncomp = new DB_PageCompiled();
     $ncomp->setPageId($npage->getPageId());
     $ncomp->setDateCompiled($now);
     $ncomp->save();
     /* Copy tags too. */
     $c = new Criteria();
     $c->add('page_id', $page->getPageId());
     $tags = DB_PageTagPeer::instance()->select($c);
     foreach ($tags as $tag) {
         $tag->setNew(true);
         $tag->setTagId(null);
         $tag->setSiteId($nsite->getSiteId());
         $tag->setPageId($npage->getPageId());
         $tag->save();
     }
     $this->pageMap[$page->getPageId()] = $npage->getPageId();
 }