protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $pages = PageTable::getInstance()->findAll(); foreach ($pages as $page) { $commit = CommitTable::getLatestCommit($page->getId()); $page->setLastUpdatedYm((int) $commit->getDateTimeObject('committed_at')->format('Ym')); $page->save(); } }
/** * updateLastUpdated() * * @return */ public function updateLastUpdated() { $commit = CommitTable::getLatestCommit($this->getId()); $this->setLastUpdated($commit->getCommittedAt()); $this->setLastUpdatedYm((int) $commit->getDateTimeObject('committed_at')->format('Ym')); $this->save(); }
// レコード取得 $t->diag('findOne***()'); $page = $table->findOneByPath('/foo/bar'); $t->ok($page instanceof Page, 'レコードの取得成功'); $t->is($page->getTitle(), 'testtitle', '取得したレコードのデータが正常'); // getFromPath $t->diag('getFromPath()'); $page = PageTable::getFromPath('/foo/bar'); $t->is($page->getTitle(), 'testtitle', '取得したレコードのデータが正常'); $t->is($page->getRepository()->getName(), 'testrepo', 'リレーション先も正しく取得'); // getListFromPath() $t->diag('getListFromPath()'); $page_rec = PageTable::getListFromPath('/foo/'); // 最終更新日時を更新しておく。 foreach ($page_rec as $pagetemp) { $commit = CommitTable::getLatestCommit($pagetemp->getId()); $pagetemp->setLastUpdated($commit->getCommittedAt()); $pagetemp->save(); } $t->ok($page_rec instanceof Doctrine_Collection, '戻り値はDoctrine_Collection'); $t->is(count($page_rec), 4, 'レコードの件数が正しい'); $page_rec = PageTable::getListFromPath('/foo/bar'); $t->is(count($page_rec), 0, '末尾にスラッシュを付加してマッチ'); $page_rec = PageTable::getListFromPath('/foo'); $t->is(count($page_rec), 4, '末尾にスラッシュを付加してマッチ'); $page1 = $page_rec[0]; $page2 = $page_rec[1]; $page3 = $page_rec[2]; $t->ok($page1->getTitle() === 'testtitle2' && $page2->getTitle() === 'testtitle3' && $page3->getTitle() === 'testtitle', '取得したレコードの順序(デフォルト:最終更新日時の降順)'); $page_rec = PageTable::getListFromPath('/foo', 'title', 'asc'); $page1 = $page_rec[0];
$t->diag('getInstance()'); $table = CommitTable::getInstance(); $t->ok($table instanceof CommitTable, 'テーブルインスタンス取得'); // レコード取得 $t->diag('findAll()'); $list = $table->findAll(); $t->is(count($list), 2, 'レコード全件取得'); // レコード取得 $t->diag('findOne***()'); $commit = $table->findOneByCommitKey('commit1'); $t->ok($commit instanceof Commit, 'レコードの取得成功'); $t->is($commit->getCommitterHandle(), 'hidenori', '取得したレコードのデータが正常'); // 最新のコミット $t->diag('getLatestCommit()'); // ページを取得しておく $page = PageTable::getInstance()->findOneByPath('/foo/bar'); $commit = CommitTable::getLatestCommit($page->getId()); $t->ok($commit instanceof Commit, 'コミットレコード取得成功'); $t->is($commit->getCommitKey(), 'commit2', 'コミット日付が新しい方のレコード'); $commit = CommitTable::getLatestCommit(-1); $t->is($commit, null, 'ページIDに対応するコミットレコードがない場合は、null'); $commit = CommitTable::getFirstCommit($page->getId()); $t->ok($commit instanceof Commit, 'コミットレコード取得成功'); $t->is($commit->getCommitKey(), 'commit1', 'コミット日付が最初のレコード'); $commit = CommitTable::getFirstCommit(-1); $t->is($commit, null, 'ページIDに対応するコミットレコードがない場合は、null'); // リレーション $commit = $table->findOneByCommitKey('commit1'); $page = $commit->getPage(); $t->ok($page instanceof Page, 'リレーション先のページオブジェクト'); $t->is($page->getPath(), '/foo/bar', 'リレーション先のページオブジェクトが正しい');