public static function getContactPage() { $page = PageTable::getInstance()->findOneByUrl('contact'); if (null === $page) { throw new LogicException(__CLASS__ . ': Contact page not found'); } return $page; }
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(); } }
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::getFirstCommit($page->getId()); $page->setFirstCommitted($commit->getCommittedAt()); $page->save(); } }
<?php // test/unit/model/doctrine/PageTableTest.php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; // test環境でDB初期化 $configuration = ProjectConfiguration::getApplicationConfiguration('taskapp', 'test', true); new sfDatabaseManager($configuration); Doctrine_Core::loadData(dirname(__FILE__) . '/PageFixture.yml'); $t = new lime_test(60); // getInstance $t->diag('getInstance()'); $table = PageTable::getInstance(); $t->ok($table instanceof PageTable, 'テーブルインスタンス取得'); // レコード取得 $t->diag('findAll()'); $list = $table->findAll(); $t->is(count($list), 4, 'レコード全件取得'); // レコード取得 $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/'); // 最終更新日時を更新しておく。
$t->is($page->getGithubUrl(), 'http://github.com/hidenorigoto/test/blob/master/bar.markdown', 'このページのgithub上のURLを取得する。'); $page2 = PageTable::getInstance()->findOneByPath('/foo/bar2'); $t->is($page2->getGithubUrl(), 'http://github.com/hidenorigoto/test/blob/master/bar2.html', 'このページのgithub上のURLを取得する。(ファイル名、タイプ加味)'); // getGithubHistoryUrl $t->diag('getGithubHistoryUrl()'); $t->is($page->getGithubHistoryUrl(), 'http://github.com/hidenorigoto/test/commits/master/bar.markdown', 'このページのgithub上のコミット履歴のURLを取得する。'); // getFormattedFirstCommitted $page = PageTable::getInstance()->findOneByPath('/foo/bar'); // page1 $t->diag('getFormattedFirstCommitted()'); $t->is($page->getFormattedFirstCommitted(), '2010/05/09', 'ページの、フォーマット済初回コミット日付'); $page = new Page(); $page->setRepository($repo); $page->setPath('/path/to2'); $page->setContentRaw('content_raw'); $page->setContentType('content_type'); $page->setContentRendered('content_rendered'); $page->setTitle('title'); $page->setIndexJson('index_json'); $page->setLastUpdated('2010/01/02 03:04:05'); $page->save(); $page = PageTable::getInstance()->findOneByPath('/path/to2'); // page1 $t->diag('getFormattedFirstCommitted()'); $t->is($page->getFormattedFirstCommitted(), '', 'ページの、フォーマット済初回コミット日付 値未設定'); $page->setFirstCommitted(0); $page->save(); $page = PageTable::getInstance()->findOneByPath('/path/to2'); // page1 $t->diag('getFormattedFirstCommitted()'); $t->is($page->getFormattedFirstCommitted(), '', 'ページの、フォーマット済初回コミット日付 値0');
<?php // test/unit/model/doctrine/CommitTest.php require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; // test環境でDB初期化 $configuration = ProjectConfiguration::getApplicationConfiguration('taskapp', 'test', true); new sfDatabaseManager($configuration); Doctrine_Core::loadData(dirname(__FILE__) . '/CommitFixture.yml'); $t = new lime_test(12); // construct $t->diag('__construct()'); $t->ok(new Commit() instanceof Commit, 'Commitインスタンス化'); $page = PageTable::getInstance()->findOneByPath('/foo/bar'); // create $t->diag('create'); $commit = new Commit(); $commit->setCommittedAt('2010/05/19 01:02:03'); $commit->setAuthorHandle('author_handle'); $commit->setAuthorEmail('author_email'); $commit->setCommitterHandle('committer_handle'); $commit->setCommitterEmail('committer_email'); $commit->setCommitKey('commit_key'); $commit->setPage($page); $commit->save(); $commit = CommitTable::getInstance()->findOneByCommitKey('commit_key'); $t->ok($commit instanceof Commit, 'レコードが正しく保存された'); $t->is($commit->getDateTimeObject('committed_at')->format('Y/m/d H:i:s'), '2010/05/19 01:02:03', 'コミット日時の保存'); $t->is($commit->getAuthorHandle(), 'author_handle', '作者ハンドルの保存'); $t->is($commit->getAuthorEmail(), 'author_email', '作者メールアドレスの保存'); $t->is($commit->getCommitterHandle(), 'committer_handle', 'コミッターハンドルの保存'); $t->is($commit->getCommitterEmail(), 'committer_email', 'コミッターメールアドレスの保存');