/** * 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(); } }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { $block = (array) $block; $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array_keys(CJTBlockModel::getCustomPins()))); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData); $blocks->update($blockData); }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { // To be used by array_intersect_key. $block = (array) $block; // Create Tables objects. $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); $blocks->update($blockData); }