예제 #1
0
    /**
     * put your comment there...
     * 
     * @param mixed $srcBackupId
     * @param mixed $desBackupId
     */
    public function copyBackupBlocks($srcBackupId, $desBackupId)
    {
        // Initialie.
        $codeFilesQuery = 'INSERT INTO #__cjtoolbox_block_files (blockId, id, name, description, `type`, code, `order`)
												 SELECT %d, id, name, description, `type`, code, `order` FROM #__cjtoolbox_block_files WHERE blockId = %d;';
        // Blocks Table & Model..
        require_once CJTOOLBOX_TABLES_PATH . '/blocks.php';
        require_once CJTOOLBOX_TABLES_PATH . '/block-pins.php';
        require_once CJTOOLBOX_MODELS_PATH . '/blocks.php';
        // Get blocks Table & Model instances.
        $blocksTable = new CJTBlocksTable($this->dbDriver);
        $blockPinsTable = new CJTBlockPinsTable($this->dbDriver);
        $blocksModel = new CJTBlocksModel();
        // Get source backup blocks.
        $blocks['fields'] = array('*');
        $blocks['filters']['backupId'] = $srcBackupId;
        $blocks['filters']['types'] = array('block', 'revision');
        // Its important to get revision blocks at the end
        // to create blocks id map.
        $blocks['orderby'] = array('type');
        $blocks = $blocksModel->getBlocks(null, $blocks['filters'], $blocks['fields'], OBJECT_K, $blocks['orderby']);
        // Prepare vars before copying.
        $desBlockId = $blocksTable->getNextId();
        // For every block give new Id and insert block and pins data.
        $blocksMap = array();
        foreach ($blocks as $id => $block) {
            // Change block Id & backupId.
            $block->id = $desBlockId++;
            $block->backupId = $desBackupId;
            // Change revision "parentId" to the new block id.
            if ($block->type == 'block') {
                // Map the old id to the new one.
                $blocksMap[$id] = $block->id;
            } else {
                if ($block->type = 'revision') {
                    // Exclude revision blocks for other types than 'block' type (e.g metabox revisions).
                    if (!isset($blocksMap[$block->parent])) {
                        continue;
                    } else {
                        $block->parent = $blocksMap[$block->parent];
                    }
                }
            }
            // Cast stdClass to array.
            $block = (array) $block;
            // Insert block.
            $blockData = array_intersect_key($block, $blocksTable->getFields());
            $blocksTable->insert($blockData);
            // Insert block Pins.
            $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories')));
            $blockPinsTable->insert($block['id'], $pinsData);
            // Copy code files.
            $this->dbDriver->insert(sprintf($codeFilesQuery, $block['id'], $id))->processQueue();
        }
    }
예제 #2
0
 /**
  * put your comment there...
  * 
  */
 public function id()
 {
     $id = false;
     // If its a normal block just get the id from the KEY!
     if ($this->type == self::BLOCK_TYPE_BACKUP) {
         $dbDriver = cssJSToolbox::getInstance()->getDBDriver();
         $blocksTable = new CJTBlocksTable($dbDriver);
         $id = $blocksTable->getNextId();
     } else {
         // If backup block generate new ID!
         $id = parent::id();
     }
     return $id;
 }
예제 #3
0
 /**
  * put your comment there...
  * 
  */
 public function reservedMetaboxBlockId()
 {
     // Reserved if only if not already taken!
     if (!($reservedId = $this->getMetaboxId())) {
         // Get Blocks table instance.
         $BlocksTable = new CJTBlocksTable($this->dbDriver);
         // Get next Id.
         $reservedId = $BlocksTable->getNextId();
         // Set metabox reserved id.
         update_post_meta($this->getPost()->ID, CJTBlocksTable::BLOCK_META_BOX_ID_META_NAME, $reservedId);
     }
     return $reservedId;
 }
예제 #4
0
 /**
  * put your comment there...
  * 
  * @param mixed $blockId
  * @param mixed $activeFileId
  */
 public function addRevision($blockId, $activeFileId)
 {
     // Create Tables objects.
     $blocks = new CJTBlocksTable($this->dbDriver);
     $pins = new CJTBlockPinsTable($this->dbDriver);
     $codeFile = new CJTBlockFilesTable($this->dbDriver);
     // We allow only up to self::MAX_REVISIONS_PER_BLOCK revisions per
     // block code files So that a single block may has up to
     // self::MAX_REVISIONS_PER_BLOCK * count(codeFiles)
     $revisions['fields'] = array('id');
     $revisions['filters'] = array('type' => 'revision', 'parent' => $blockId, 'masterFile' => $activeFileId);
     $revisions = $blocks->get(null, $revisions['fields'], $revisions['filters']);
     // If revisions reached self::MAX_REVISIONS_PER_BLOCK delete first one.
     if (count($revisions) == self::MAX_REVISIONS_PER_BLOCK) {
         $this->delete(array_shift($revisions)->id);
     }
     // Get block data.
     $block['fields'] = array('id', 'lastModified', 'pinPoint', 'links', 'expressions');
     // get() developed to return multiple blocks, fetch the first.
     $result = $blocks->get($blockId, $block['fields']);
     $block = reset($result);
     // Set other fields.
     $block->location = $block->state = '';
     $block->parent = $blockId;
     $block->type = 'revision';
     $block->created = current_time('mysql');
     $block->owner = get_current_user_id();
     $block->masterFile = $activeFileId;
     // Only the revisioned code file would be exists and must be
     // used as the masterFile!
     $block->id = $blocks->getNextId();
     // Get new id for revision rrecord.
     // Add block data.
     $blocks->insert($block);
     // Get block pins and insert pins for the revision block.
     $blockPins = $pins->get($blockId);
     if (!empty($blockPins)) {
         $pins->insertRaw($block->id, $blockPins);
     }
     // Revision current ActiveFileId code record.
     // Simply, get a copy of it from the target block
     // and assign the copy to the new created block revision.
     $codeFile->set('id', $activeFileId)->set('blockId', $blockId)->load()->set('blockId', $block->id)->save(true, true);
 }