public function fixPostAction() { echo 'fix posts' . PHP_EOL; $postTbl = new Book_Model_DbTable_Posts(); $postSelect = $postTbl->select()->where('rawpost_id > 0'); $postSelect->limit(200); $rawPostIds = array(); $posts = $postTbl->fetchAll($postSelect); echo 'number of posts : ' . count($posts) . PHP_EOL; foreach ($posts as $post) { array_push($rawPostIds, $post->rawpost_id); } $rawPostTbl = new Book_Model_DbTable_Rawposts(); $rawPostTbl->delete(array('rawpost_id IN (?)' => $rawPostIds)); foreach ($posts as $post) { $post->delete(); } echo 'The posts have been deleted !' . PHP_EOL; die; }
public function importRawPosts() { try { $postTbl = new Book_Model_DbTable_Posts(); $select = $postTbl->select(); $select->from($postTbl->info('name'), new Zend_Db_Expr('MAX(`rawpost_id`) as max_rawpost_id')); $data = $select->query()->fetch(); $maxRawpostId = (int) $data['max_rawpost_id']; $bookTbl = new Book_Model_DbTable_Books(); $rawPostTbl = new Book_Model_DbTable_Rawposts(); $rawPostSelect = $rawPostTbl->select(); $rawPostSelect->where('rawpost_id > ?', $maxRawpostId); $rawBookTbl = new Book_Model_DbTable_Rawbooks(); foreach ($rawPostTbl->fetchAll($rawPostSelect) as $rawPost) { $data = array('post_name' => $rawPost->name, 'content' => $rawPost->content, 'user_id' => 1, 'rawpost_id' => $rawPost->rawpost_id); if (!empty($rawPost->book_link_id)) { $book = $rawBookTbl->getBookFromBookLinkId($rawPost->book_link_id); if (!empty($book)) { $data['parent_type'] = $book->getType(); $data['parent_id'] = $book->getIdentity(); } } $post = $postTbl->createRow($data); $post->save(); } return true; } catch (Exception $e) { throw $e; } }