diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index f28671e41..ec49c81d4 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1043,7 +1043,7 @@ class Doctrine_Export extends Doctrine_Connection_Module // check if class is an instance of Doctrine_Record and not abstract // class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord) // we have to recursively iterate through the class parents just to be sure that the classes using for example - // column aggregation inheritance are properly exporterd to database + // column aggregation inheritance are properly exported to database while ($class->isAbstract() || ! $class->isSubclassOf($parent) || ! $class->hasMethod('setTableDefinition') || @@ -1057,11 +1057,12 @@ class Doctrine_Export extends Doctrine_Connection_Module } if ($class === false) { - continue; + continue; } $record = new $name(); $table = $record->getTable(); + $data = $table->getExportableFormat(); $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); @@ -1071,12 +1072,38 @@ class Doctrine_Export extends Doctrine_Connection_Module } else { $sql[] = $query; } + if ($table->getAttribute(Doctrine::ATTR_EXPORT) & Doctrine::EXPORT_PLUGINS) { + $sql = array_merge($sql, $this->exportPluginsSql($table)); + } } $sql = array_unique($sql); rsort($sql); return $sql; } + /** + * exportPluginsSql + * exports plugin tables for given table + * + * @param Doctrine_Table $table the table in which the plugins belong to + * @return array an array of sql strings + */ + public function exportPluginsSql(Doctrine_Table $table) + { + $sql = array(); + + foreach ($table->getTemplates() as $name => $template) { + $table = $template->getPlugin()->getOption('pluginTable'); + + $data = $table->getExportableFormat(); + + $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); + + $sql = array_merge($sql, (array) $query); + } + + return $sql; + } /** * exportSql * returns the sql for exporting Doctrine_Record classes to a schema diff --git a/lib/Doctrine/I18n.php b/lib/Doctrine/I18n.php index 86a2e4910..48a8e80b7 100644 --- a/lib/Doctrine/I18n.php +++ b/lib/Doctrine/I18n.php @@ -36,6 +36,7 @@ class Doctrine_I18n extends Doctrine_Plugin 'fields' => array(), 'generateFiles' => false, 'table' => false, + 'pluginTable' => false, ); protected $_auditTable; @@ -109,6 +110,8 @@ class Doctrine_I18n extends Doctrine_Plugin if ( ! $this->_options['generateFiles']) { eval($def); } + $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']); + return true; } } diff --git a/lib/Doctrine/Template.php b/lib/Doctrine/Template.php index e966bd4ee..7ec712f27 100644 --- a/lib/Doctrine/Template.php +++ b/lib/Doctrine/Template.php @@ -36,6 +36,9 @@ class Doctrine_Template extends Doctrine_Record_Abstract * @param Doctrine_Record $_invoker the record that invoked the last delegated call */ protected $_invoker; + + + protected $_plugin; /** * setTable * @@ -77,6 +80,14 @@ class Doctrine_Template extends Doctrine_Record_Abstract { return $this->_invoker; } + public function get() + { + throw new Exception(); + } + public function getPlugin() + { + return $this->_plugin; + } public function setUp() {