Example #1
0
 public function duplicateCollection()
 {
     $db = Loader::db();
     $dh = Loader::helper('date');
     $cDate = $dh->getOverridableNow();
     $v = array($cDate, $cDate, $this->cHandle);
     $r = $db->query('insert into Collections (cDateAdded, cDateModified, cHandle) values (?, ?, ?)', $v);
     $newCID = $db->Insert_ID();
     if ($r) {
         // first, we get the creation date of the active version in this collection
         //$q = "select cvDateCreated from CollectionVersions where cvIsApproved = 1 and cID = {$this->cID}";
         //$dcOriginal = $db->getOne($q);
         // now we create the query that will grab the versions we're going to copy
         $qv = "select * from CollectionVersions where cID = '{$this->cID}' order by cvDateCreated asc";
         // now we grab all of the current versions
         $rv = $db->query($qv);
         $cvList = array();
         while ($row = $rv->fetchRow()) {
             // insert
             $cvList[] = $row['cvID'];
             $cDate = date('Y-m-d H:i:s', strtotime($cDate) + 1);
             $vv = array($newCID, $row['cvID'], $row['cvName'], $row['cvHandle'], $row['cvDescription'], $row['cvDatePublic'], $cDate, $row['cvComments'], $row['cvAuthorUID'], $row['cvIsApproved'], $row['pThemeID'], $row['pTemplateID']);
             $qv = 'insert into CollectionVersions (cID, cvID, cvName, cvHandle, cvDescription, cvDatePublic, cvDateCreated, cvComments, cvAuthorUID, cvIsApproved, pThemeID, pTemplateID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
             $db->query($qv, $vv);
         }
         $ql = "select * from CollectionVersionBlockStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['bID'], $row['arHandle'], $row['issID']);
             $ql = 'insert into CollectionVersionBlockStyles (cID, cvID, bID, arHandle, issID) values (?, ?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         $ql = "select * from CollectionVersionAreaStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['arHandle'], $row['issID']);
             $ql = 'insert into CollectionVersionAreaStyles (cID, cvID, arHandle, issID) values (?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         $ql = "select * from CollectionVersionThemeCustomStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['pThemeID'], $row['scvlID'], $row['preset'], $row['sccRecordID']);
             $ql = 'insert into CollectionVersionThemeCustomStyles (cID, cvID, pThemeID, scvlID, preset, sccRecordID) values (?, ?, ?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         // now we grab all the blocks we're going to need
         $cvList = implode(',', $cvList);
         $q = "select bID, cvID, arHandle, cbDisplayOrder, cbOverrideAreaPermissions, cbIncludeAll from CollectionVersionBlocks where cID = '{$this->cID}' and cvID in ({$cvList})";
         $r = $db->query($q);
         while ($row = $r->fetchRow()) {
             $v = array($newCID, $row['cvID'], $row['bID'], $row['arHandle'], $row['cbDisplayOrder'], 0, $row['cbOverrideAreaPermissions'], $row['cbIncludeAll']);
             $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbDisplayOrder, isOriginal, cbOverrideAreaPermissions, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?, ?)';
             $db->query($q, $v);
             if ($row['cbOverrideAreaPermissions'] != 0) {
                 $q2 = "select paID, pkID from BlockPermissionAssignments where cID = '{$this->cID}' and bID = '{$row['bID']}' and cvID = '{$row['cvID']}'";
                 $r2 = $db->query($q2);
                 while ($row2 = $r2->fetchRow()) {
                     $db->Replace('BlockPermissionAssignments', array('cID' => $newCID, 'cvID' => $row['cvID'], 'bID' => $row['bID'], 'paID' => $row2['paID'], 'pkID' => $row2['pkID']), array('cID', 'cvID', 'bID', 'paID', 'pkID'), true);
                 }
             }
         }
         // duplicate any attributes belonging to the collection
         $v = array($this->getCollectionID());
         $q = 'select akID, cvID, avID from CollectionAttributeValues where cID = ?';
         $r = $db->query($q, $v);
         while ($row = $r->fetchRow()) {
             $v2 = array($row['akID'], $row['cvID'], $row['avID'], $newCID);
             $db->query('insert into CollectionAttributeValues (akID, cvID, avID, cID) values (?, ?, ?, ?)', $v2);
         }
         return Collection::getByID($newCID);
     }
 }
 /**
  * @inheritdoc
  */
 public function collection(Collection $collection, $code = Response::HTTP_OK, $headers = array())
 {
     if (!$this->app) {
         throw new \RuntimeException('Cannot resolve collections without a reference to the application');
     }
     $request = $this->request;
     if ($collection->isError() && $collection->getError() == COLLECTION_NOT_FOUND) {
         if ($response = $this->collectionNotFound($collection, $request, $headers)) {
             return $response;
         }
     }
     if ($collection->getCollectionPath() != '/page_not_found') {
         if (!isset($collection->cPathFetchIsCanonical) || !$collection->cPathFetchIsCanonical) {
             // Handle redirect URL (additional page paths)
             /** @var Url $url */
             $url = $this->app->make('url/manager')->resolve([$collection]);
             $query = $url->getQuery();
             $query->modify($request->getQueryString());
             $url = $url->setQuery($query);
             return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY, $headers);
         }
     }
     // maintenance mode
     if ($collection->getCollectionPath() != '/login') {
         $smm = $this->config->get('concrete.maintenance_mode');
         if ($smm == 1 && !Key::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) {
             $v = new View('/frontend/maintenance_mode');
             $router = $this->app->make(RouterInterface::class);
             $tmpTheme = $router->getThemeByRoute('/frontend/maintenance_mode');
             $v->setViewTheme($tmpTheme[0]);
             $v->addScopeItems(['c' => $collection]);
             $request->setCurrentPage($collection);
             if (isset($tmpTheme[1])) {
                 $v->setViewTemplate($tmpTheme[1]);
             }
             return $this->view($v, $code, $headers);
         }
     }
     if ($collection->getCollectionPointerExternalLink() != '') {
         return $this->redirect($collection->getCollectionPointerExternalLink());
     }
     $cp = new Checker($collection);
     if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) {
         return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers);
     }
     if (!$collection->isActive() && !$cp->canViewPageVersions()) {
         return $this->notFound('', Response::HTTP_NOT_FOUND, $headers);
     }
     $scheduledVersion = Version::get($collection, "SCHEDULED");
     if ($publishDate = $scheduledVersion->cvPublishDate) {
         $datetime = $this->app->make('helper/date');
         $now = $datetime->date('Y-m-d G:i:s');
         if (strtotime($now) >= strtotime($publishDate)) {
             $scheduledVersion->approve();
             $collection->loadVersionObject('ACTIVE');
         }
     }
     if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) {
         $collection->loadVersionObject('RECENT');
     }
     $vp = new Checker($collection->getVersionObject());
     // returns the $vp object, which we then check
     if (is_object($vp) && $vp->isError()) {
         switch ($vp->getError()) {
             case COLLECTION_NOT_FOUND:
                 return $this->notFound('', Response::HTTP_NOT_FOUND, $headers);
                 break;
             case COLLECTION_FORBIDDEN:
                 return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers);
                 break;
         }
     }
     // Now that we've passed all permissions checks, and we have a page, we check to see if we
     // ought to redirect based on base url or trailing slash settings
     $cms = $this->app;
     $site = $this->app['site']->getSite();
     $response = $cms->handleCanonicalURLRedirection($request, $site);
     if (!$response) {
         $response = $cms->handleURLSlashes($request, $site);
     }
     if (isset($response)) {
         return $response;
     }
     $dl = $cms->make('multilingual/detector');
     if ($dl->isEnabled()) {
         $dl->setupSiteInterfaceLocalization($collection);
     }
     if (!$request->getPath() && $request->isMethod('GET') && !$request->query->has('cID')) {
         // This is a request to the home page –http://www.mysite.com/
         // First, we check to see if we need to redirect to a default multilingual section.
         if ($dl->isEnabled() && $site->getConfigRepository()->get('multilingual.redirect_home_to_default_locale')) {
             // Let's retrieve the default language
             $ms = $dl->getPreferredSection();
             if (is_object($ms)) {
                 return $this->redirect(\URL::to($ms));
             }
         }
         // Otherwise, let's check to see if our home page, which we have loaded already, has a path (like /en)
         // If it does, we'll redirect to the path.
         if ($collection->getCollectionPath() != '') {
             return $this->redirect(\URL::to($collection));
         }
     }
     $request->setCurrentPage($collection);
     $c = $collection;
     // process.php needs this
     require DIR_BASE_CORE . '/bootstrap/process.php';
     $u = new User();
     // On page view event.
     $pe = new Event($collection);
     $pe->setUser($u);
     $pe->setRequest($request);
     $this->app['director']->dispatch('on_page_view', $pe);
     // Core menu items
     $item = new RelationListItem();
     $menu = $this->app->make('helper/concrete/ui/menu');
     $menu->addMenuItem($item);
     $controller = $collection->getPageController();
     // we update the current page with the one bound to this controller.
     $collection->setController($controller);
     return $this->controller($controller);
 }
 /**
  * Track a list of blocks for a collection
  * @param \Concrete\Core\Page\Collection\Collection $collection
  * @param Block[]|BlockController[] $blocks
  */
 private function trackBlocks(Collection $collection, array $blocks)
 {
     $version = $collection->getVersionID();
     $buffer = 0;
     foreach ($blocks as $block) {
         if ($block instanceof Controller) {
             $controller = $block;
             $block = $controller->getBlockObject();
         }
         if ($block->getBlockTypeHandle() == BLOCK_HANDLE_STACK_PROXY) {
             if (!$controller) {
                 $controller = $block->getController();
             }
             $this->persist($controller->getStackID(), $collection->getCollectionID(), $version, $block->getBlockID());
             $buffer++;
         }
         if ($buffer > 2) {
             $this->manager->flush();
             $buffer = 0;
         }
     }
     if ($buffer) {
         // Sometimes you just need an extra flush...
         $this->manager->flush();
     }
 }
Example #4
0
 public function setPropertiesFromArray($arr)
 {
     return parent::setPropertiesFromArray($arr);
 }
 /**
  * Forget about a collection object
  * @param \Concrete\Core\Page\Collection\Collection $collection
  */
 private function forgetCollection(Collection $collection)
 {
     $query_builder = $this->manager->createQueryBuilder();
     $query_builder->delete(FileUsageRecord::class, 'r')->where('r.collection_id = :collection_id')->setParameter('collection_id', $collection->getCollectionID())->getQuery()->execute();
 }
Example #6
0
 private function countVersions(Collection $c)
 {
     /** @var Connection $database */
     $database = $this->app['database']->connection();
     $count = $database->fetchColumn('select count(cvID) from CollectionVersions where cID = :cID', [':cID' => $c->getCollectionID()]);
     return $count;
 }