From fb5fb7eb524f73dc1c75f63842e264d58fe71c58 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 27 Apr 2009 17:12:08 -0400 Subject: [PATCH] Initial implementation of comments with doctrine. Signed-off-by: Edward Z. Yang --- .gitignore | 4 ++++ XHTMLCompiler.php | 2 +- common.php | 19 ++++++++++++++---- config.default.php | 6 ++++++ functions.php | 14 ++++++++++++- generate.php | 13 ++++++++++++ models/Comment.php | 16 +++++++++++++++ models/generated/BaseComment.php | 43 ++++++++++++++++++++++++++++++++++++++++ schema.yml | 18 +++++++++++++++++ 9 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 generate.php create mode 100644 models/Comment.php create mode 100644 models/generated/BaseComment.php create mode 100644 schema.yml diff --git a/.gitignore b/.gitignore index eb6fad4..63e91df 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ # Cache/Testing /cache/svn/log/*.ser /tests/tmp/* + +# Doctrine +data.db +test.php diff --git a/XHTMLCompiler.php b/XHTMLCompiler.php index 6631cfe..8717ee9 100644 --- a/XHTMLCompiler.php +++ b/XHTMLCompiler.php @@ -58,7 +58,7 @@ class XHTMLCompiler protected $configKeys = array('allowed_dirs', 'directory_index', 'indexed_dirs', 'web_path', 'web_domain', 'viewvc_url', 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email', 'from_email', - 'error_log', 'error_mute', 'configdoc', 'smtp_transport'); + 'error_log', 'error_mute', 'configdoc', 'smtp_transport', 'dsn'); protected $config = array(); protected $filterManager; diff --git a/common.php b/common.php index 8f4358a..c361231 100644 --- a/common.php +++ b/common.php @@ -33,11 +33,8 @@ require_once 'XHTMLCompiler/TextFilter.php'; require_once 'XHTMLCompiler/DOMFilter.php'; require_once 'XHTMLCompiler/DOMFilter/NewsBase.php'; -// load external libraries that we *need* +// needed for error reporting require_once 'external/swiftmailer/lib/swift_required.php'; -require_once 'external/phpgit/library/Git.php'; -require_once 'external/htmlpurifier/library/HTMLPurifier.auto.php'; -require_once 'external/htmlpurifier/extras/HTMLPurifierExtras.auto.php'; set_exception_handler('xhtmlcompiler_exception_handler'); $xc = XHTMLCompiler::getInstance(); // invoke the super-object @@ -47,3 +44,17 @@ if($xc->getConf('debug')) { restore_error_handler(); ini_set('display_errors', true); } + +require_once 'external/phpgit/library/Git.php'; +require_once 'external/htmlpurifier/library/HTMLPurifier.auto.php'; +require_once 'external/htmlpurifier/extras/HTMLPurifierExtras.auto.php'; + +// load Doctrine +require_once 'external/doctrine/lib/Doctrine.php'; +spl_autoload_register(array('Doctrine', 'autoload')); + +Doctrine::loadModels('xhtml-compiler/models/generated'); +Doctrine::loadModels('xhtml-compiler/models'); + +Doctrine_Manager::connection($xc->getConf('dsn')); + diff --git a/config.default.php b/config.default.php index 05f250d..4752674 100644 --- a/config.default.php +++ b/config.default.php @@ -108,3 +108,9 @@ $configdoc = 'http://htmlpurifier.org/live/configdoc/plain.html#%s'; // default should "just work". $smtp_transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t'); +// ** Data source name +// See http://www.doctrine-project.org/documentation/manual/1_1/en/introduction-to-connections +// for information on the syntax. By default, we'll dump everything into +// an sqlite database, which is not the best in terms of scalability. +$dsn = 'sqlite:///' . dirname(__FILE__) . '/data.db'; + diff --git a/functions.php b/functions.php index 0ac01d5..7d869d5 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,13 @@ paint((string) $e); + return; + } + $error_xsl = $xc->getConf('error_xsl'); // extract information out of exception diff --git a/generate.php b/generate.php new file mode 100644 index 0000000..d64bd76 --- /dev/null +++ b/generate.php @@ -0,0 +1,13 @@ + + * @version SVN: $Id$ + */ +class Comment extends BaseComment +{ + +} \ No newline at end of file diff --git a/models/generated/BaseComment.php b/models/generated/BaseComment.php new file mode 100644 index 0000000..6c8f551 --- /dev/null +++ b/models/generated/BaseComment.php @@ -0,0 +1,43 @@ + + * @version SVN: $Id$ + */ +abstract class BaseComment extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->setTableName('comment'); + $this->hasColumn('id', 'integer', null, array('type' => 'integer', 'primary' => true, 'autoincrement' => true)); + $this->hasColumn('username', 'string', null, array('type' => 'string')); + $this->hasColumn('time', 'timestamp', null, array('type' => 'timestamp')); + $this->hasColumn('ip', 'string', null, array('type' => 'string')); + $this->hasColumn('parent_id', 'integer', null, array('type' => 'integer')); + $this->hasColumn('content', 'clob', null, array('type' => 'clob')); + } + + public function setUp() + { + $this->hasOne('Comment as Parent', array('local' => 'parent_id', + 'foreign' => 'id')); + + $this->hasMany('Comment', array('local' => 'id', + 'foreign' => 'parent_id')); + } +} \ No newline at end of file diff --git a/schema.yml b/schema.yml new file mode 100644 index 0000000..eb47c1d --- /dev/null +++ b/schema.yml @@ -0,0 +1,18 @@ +--- + +Comment: + columns: + id: + type: integer + primary: true + autoincrement: true + username: string + time: timestamp + ip: string + parent_id: integer + content: clob + relations: + Parent: + class: Comment + local: parent_id + foreign: id -- 2.11.4.GIT