/** * Parse and process the data content. * * insert => insert rows. * update => make some changes into the rows. * delete => delete rows. * * The values ##Module_id## are reemplaces with the moduleId value * * @param array $array Array from the json data with the changes. * * @return void */ private function _processData($array) { foreach ($array as $tableName => $content) { foreach ($content as $action => $rows) { switch ($action) { case 'insert': foreach ($rows as $data) { $relations = array(); if (isset($data['_relations'])) { $relations = $data['_relations']; unset($data['_relations']); } $data = $this->_convertModulesId($data); $newId = $this->_tableManager->insertRow($tableName, $data); if (!empty($relations)) { $this->_relations[] = array('newId' => $newId, 'content' => $relations); } } break; case 'update': foreach ($rows as $data) { if (empty($data['_sqlWhere'])) { $where = null; } else { $where = $data['_sqlWhere']; } unset($data['_sqlWhere']); $data = $this->_convertModulesId($data); $this->_tableManager->updateRows($tableName, $data, $where); } break; case 'delete': foreach ($rows as $code => $where) { if (empty($code)) { $where = null; } $data = $this->_convertModulesId($data); $this->_tableManager->deleteRows($tableName, $where); } break; } } } }
/** * Insert all the searc_words and search_word_module values. * * @return void */ private function _executeSearchWordsInsert() { // Words $dbFields = array('word', 'count'); $dbValues = array(); foreach ($this->_searchWord as $word => $data) { $dbValues[] = array($word, $data['count']); } $ids = $this->_tableManager->insertMultipleRows('search_words', $dbFields, $dbValues, true); // Relations $dbFields = array('item_id', 'module_id', 'word_id'); $dbValues = array(); foreach ($this->_searchWord as $word => $data) { $id = array_shift($ids); foreach ($data['pair'] as $pair) { $dbValues[] = array($pair[0], $pair[1], $id); } if (count($dbValues) > 100000) { $this->_tableManager->insertMultipleRows('search_word_module', $dbFields, $dbValues); $dbValues = array(); } } if (!empty($dbValues)) { $this->_tableManager->insertMultipleRows('search_word_module', $dbFields, $dbValues); } }
/** * Delete all the entries for the current Module and drop the table. * * @return boolean True on a sucessful delete. */ public function deleteModule() { $table = $this->_getModuleName(); $where = $this->getAdapter()->quoteInto('table_name = ?', $table); $result = $this->fetchAll($where); foreach ($result as $record) { $record->delete(); } $tableManager = new Phprojekt_Table(Phprojekt::getInstance()->getDb()); return $tableManager->dropTable($table); }