Deprecation: This isn't needed anymore by switching to doctrine.
Example #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         // validate fields
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = BackendContentBlocksModel::getMaximumId() + 1;
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['template'] = count($this->templates) > 1 ? $fields['template']->getValue() : $this->templates[0];
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['hidden'] = $fields['hidden']->getValue() ? 'N' : 'Y';
             $item['status'] = 'active';
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $item['revision_id'] = BackendContentBlocksModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Example #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendContentBlocksModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendContentBlocksModel::get($this->id);
         // delete item
         BackendContentBlocksModel::delete($this->id);
         // trigger event
         BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         // item was deleted, so redirect
         $this->redirect(BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         // no item found, redirect to the overview with an error
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }
Example #3
0
 /**
  * Copy pages
  *
  * @param string $from The language code to copy the pages from.
  * @param string $to   The language code we want to copy the pages to.
  */
 public static function copy($from, $to)
 {
     // get db
     $db = BackendModel::getContainer()->get('database');
     // copy contentBlocks and get copied contentBlockIds
     $contentBlockIds = BackendContentBlocksModel::copy($from, $to);
     // define old block ids
     $contentBlockOldIds = array_keys($contentBlockIds);
     // get all old pages
     $ids = $db->getColumn('SELECT id
          FROM pages AS i
          WHERE i.language = ? AND i.status = ?', array($to, 'active'));
     // any old pages
     if (!empty($ids)) {
         // delete existing pages
         foreach ($ids as $id) {
             // redefine
             $id = (int) $id;
             // get revision ids
             $revisionIDs = (array) $db->getColumn('SELECT i.revision_id
                  FROM pages AS i
                  WHERE i.id = ? AND i.language = ?', array($id, $to));
             // get meta ids
             $metaIDs = (array) $db->getColumn('SELECT i.meta_id
                  FROM pages AS i
                  WHERE i.id = ? AND i.language = ?', array($id, $to));
             // delete meta records
             if (!empty($metaIDs)) {
                 $db->delete('meta', 'id IN (' . implode(',', $metaIDs) . ')');
             }
             // delete blocks and their revisions
             if (!empty($revisionIDs)) {
                 $db->delete('pages_blocks', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
             }
             // delete page and the revisions
             if (!empty($revisionIDs)) {
                 $db->delete('pages', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
             }
         }
     }
     // delete search indexes
     $db->delete('search_index', 'module = ? AND language = ?', array('pages', $to));
     // get all active pages
     $ids = BackendModel::getContainer()->get('database')->getColumn('SELECT id
          FROM pages AS i
          WHERE i.language = ? AND i.status = ?', array($from, 'active'));
     // loop
     foreach ($ids as $id) {
         // get data
         $sourceData = self::get($id, null, $from);
         // get and build meta
         $meta = $db->getRecord('SELECT *
              FROM meta
              WHERE id = ?', array($sourceData['meta_id']));
         // remove id
         unset($meta['id']);
         // init page
         $page = array();
         // build page
         $page['id'] = $sourceData['id'];
         $page['user_id'] = BackendAuthentication::getUser()->getUserId();
         $page['parent_id'] = $sourceData['parent_id'];
         $page['template_id'] = $sourceData['template_id'];
         $page['meta_id'] = (int) $db->insert('meta', $meta);
         $page['language'] = $to;
         $page['type'] = $sourceData['type'];
         $page['title'] = $sourceData['title'];
         $page['navigation_title'] = $sourceData['navigation_title'];
         $page['navigation_title_overwrite'] = $sourceData['navigation_title_overwrite'];
         $page['hidden'] = $sourceData['hidden'];
         $page['status'] = 'active';
         $page['publish_on'] = BackendModel::getUTCDate();
         $page['created_on'] = BackendModel::getUTCDate();
         $page['edited_on'] = BackendModel::getUTCDate();
         $page['allow_move'] = $sourceData['allow_move'];
         $page['allow_children'] = $sourceData['allow_children'];
         $page['allow_edit'] = $sourceData['allow_edit'];
         $page['allow_delete'] = $sourceData['allow_delete'];
         $page['sequence'] = $sourceData['sequence'];
         $page['data'] = $sourceData['data'] !== null ? serialize($sourceData['data']) : null;
         // insert page, store the id, we need it when building the blocks
         $revisionId = self::insert($page);
         // init var
         $blocks = array();
         $hasBlock = $sourceData['has_extra'] == 'Y';
         // get the blocks
         $sourceBlocks = self::getBlocks($id, null, $from);
         // loop blocks
         foreach ($sourceBlocks as $sourceBlock) {
             // build block
             $block = $sourceBlock;
             $block['revision_id'] = $revisionId;
             $block['created_on'] = BackendModel::getUTCDate();
             $block['edited_on'] = BackendModel::getUTCDate();
             if (in_array($block['extra_id'], $contentBlockOldIds)) {
                 $block['extra_id'] = $contentBlockIds[$block['extra_id']];
             }
             // add block
             $blocks[] = $block;
         }
         // insert the blocks
         self::insertBlocks($blocks, $hasBlock);
         // init var
         $text = '';
         // build search-text
         foreach ($blocks as $block) {
             $text .= ' ' . $block['html'];
         }
         // add
         BackendSearchModel::saveIndex('Pages', (int) $page['id'], array('title' => $page['title'], 'text' => $text), $to);
         // get tags
         $tags = BackendTagsModel::getTags('pages', $id, 'string', $from);
         // save tags
         if ($tags != '') {
             $saveWorkingLanguage = BL::getWorkingLanguage();
             // If we don't set the working language to the target language,
             // BackendTagsModel::getURL() will use the current working
             // language, possibly causing unnecessary '-2' suffixes in
             // tags.url
             BL::setWorkingLanguage($to);
             BackendTagsModel::saveTags($page['id'], $tags, 'pages', $to);
             BL::setWorkingLanguage($saveWorkingLanguage);
         }
     }
     // build cache
     self::buildCache($to);
 }