Author: david
Date: Mon Jul 4 11:50:59 2011
New Revision: 9241
Log:
Drop nested set columns from note table - not used.
Modified:
trunk/config/schema.yml
trunk/data/sql/lib.model.schema.sql
trunk/lib/model/map/NoteTableMap.php
trunk/lib/model/om/BaseNote.php
Modified: trunk/config/schema.yml
==============================================================================
--- trunk/config/schema.yml Thu Jun 30 10:23:54 2011 (r9240)
+++ trunk/config/schema.yml Mon Jul 4 11:50:59 2011 (r9241)
@@ -181,9 +181,6 @@
type_id: { type: integer, foreignTable: term, foreignReference: id,
onDelete: setnull }
scope: varchar(255)
user_id:
- parent_id: { type: integer, foreignTable: note, foreignReference: id }
- lft: { type: integer, required: true, nestedSetLeftKey: true }
- rgt: { type: integer, required: true, nestedSetRightKey: true }
created_at:
updated_at:
Modified: trunk/data/sql/lib.model.schema.sql
==============================================================================
--- trunk/data/sql/lib.model.schema.sql Thu Jun 30 10:23:54 2011 (r9240)
+++ trunk/data/sql/lib.model.schema.sql Mon Jul 4 11:50:59 2011 (r9241)
@@ -561,9 +561,6 @@
`type_id` INTEGER,
`scope` VARCHAR(255),
`user_id` INTEGER,
- `parent_id` INTEGER,
- `lft` INTEGER NOT NULL,
- `rgt` INTEGER NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
`source_culture` VARCHAR(7) NOT NULL,
@@ -583,11 +580,7 @@
INDEX `note_FI_3` (`user_id`),
CONSTRAINT `note_FK_3`
FOREIGN KEY (`user_id`)
- REFERENCES `user` (`id`),
- INDEX `note_FI_4` (`parent_id`),
- CONSTRAINT `note_FK_4`
- FOREIGN KEY (`parent_id`)
- REFERENCES `note` (`id`)
+ REFERENCES `user` (`id`)
)Engine=InnoDB;
#-----------------------------------------------------------------------------
Modified: trunk/lib/model/map/NoteTableMap.php
==============================================================================
--- trunk/lib/model/map/NoteTableMap.php Thu Jun 30 10:23:54 2011
(r9240)
+++ trunk/lib/model/map/NoteTableMap.php Mon Jul 4 11:50:59 2011
(r9241)
@@ -40,9 +40,6 @@
$this->addForeignKey('TYPE_ID', 'typeId', 'INTEGER', 'term',
'ID', false, null, null);
$this->addColumn('SCOPE', 'scope', 'VARCHAR', false, 255, null);
$this->addForeignKey('USER_ID', 'userId', 'INTEGER', 'user',
'ID', false, null, null);
- $this->addForeignKey('PARENT_ID', 'parentId', 'INTEGER',
'note', 'ID', false, null, null);
- $this->addColumn('LFT', 'lft', 'INTEGER', true, null, null);
- $this->addColumn('RGT', 'rgt', 'INTEGER', true, null, null);
$this->addColumn('CREATED_AT', 'createdAt', 'TIMESTAMP', true,
null, null);
$this->addColumn('UPDATED_AT', 'updatedAt', 'TIMESTAMP', true,
null, null);
$this->addColumn('SOURCE_CULTURE', 'sourceCulture', 'VARCHAR',
true, 7, null);
@@ -59,8 +56,6 @@
$this->addRelation('object', 'object', RelationMap::MANY_TO_ONE,
array('object_id' => 'id', ), 'CASCADE', null);
$this->addRelation('term', 'term', RelationMap::MANY_TO_ONE,
array('type_id' => 'id', ), 'SET NULL', null);
$this->addRelation('user', 'user', RelationMap::MANY_TO_ONE,
array('user_id' => 'id', ), null, null);
- $this->addRelation('noteRelatedByparentId', 'note',
RelationMap::MANY_TO_ONE, array('parent_id' => 'id', ), null, null);
- $this->addRelation('noteRelatedByparentId', 'note',
RelationMap::ONE_TO_MANY, array('id' => 'parent_id', ), null, null);
$this->addRelation('noteI18n', 'noteI18n', RelationMap::ONE_TO_MANY,
array('id' => 'id', ), 'CASCADE', null);
} // buildRelations()
Modified: trunk/lib/model/om/BaseNote.php
==============================================================================
--- trunk/lib/model/om/BaseNote.php Thu Jun 30 10:23:54 2011 (r9240)
+++ trunk/lib/model/om/BaseNote.php Mon Jul 4 11:50:59 2011 (r9241)
@@ -11,9 +11,6 @@
TYPE_ID = 'note.TYPE_ID',
SCOPE = 'note.SCOPE',
USER_ID = 'note.USER_ID',
- PARENT_ID = 'note.PARENT_ID',
- LFT = 'note.LFT',
- RGT = 'note.RGT',
CREATED_AT = 'note.CREATED_AT',
UPDATED_AT = 'note.UPDATED_AT',
SOURCE_CULTURE = 'note.SOURCE_CULTURE',
@@ -26,9 +23,6 @@
$criteria->addSelectColumn(QubitNote::TYPE_ID);
$criteria->addSelectColumn(QubitNote::SCOPE);
$criteria->addSelectColumn(QubitNote::USER_ID);
- $criteria->addSelectColumn(QubitNote::PARENT_ID);
- $criteria->addSelectColumn(QubitNote::LFT);
- $criteria->addSelectColumn(QubitNote::RGT);
$criteria->addSelectColumn(QubitNote::CREATED_AT);
$criteria->addSelectColumn(QubitNote::UPDATED_AT);
$criteria->addSelectColumn(QubitNote::SOURCE_CULTURE);
@@ -48,7 +42,7 @@
public static function getFromRow(array $row)
{
$keys = array();
- $keys['id'] = $row[10];
+ $keys['id'] = $row[7];
$key = serialize($keys);
if (!isset(self::$notes[$key]))
@@ -115,23 +109,6 @@
return $affectedRows;
}
- public static function addOrderByPreorder(Criteria $criteria, $order =
Criteria::ASC)
- {
- if ($order == Criteria::DESC)
- {
- return $criteria->addDescendingOrderByColumn(QubitNote::LFT);
- }
-
- return $criteria->addAscendingOrderByColumn(QubitNote::LFT);
- }
-
- public static function addRootsCriteria(Criteria $criteria)
- {
- $criteria->add(QubitNote::PARENT_ID);
-
- return $criteria;
- }
-
protected
$tables = array();
@@ -209,11 +186,6 @@
}
}
- if ('notesRelatedByparentId' == $name)
- {
- return true;
- }
-
if ('noteI18ns' == $name)
{
return true;
@@ -232,16 +204,6 @@
{
}
- if ('ancestors' == $name)
- {
- return true;
- }
-
- if ('descendants' == $name)
- {
- return true;
- }
-
throw new sfException("Unknown record property \"$name\" on
\"".get_class($this).'"');
}
@@ -283,23 +245,6 @@
}
}
- if ('notesRelatedByparentId' == $name)
- {
- if (!isset($this->refFkValues['notesRelatedByparentId']))
- {
- if (!isset($this->id))
- {
- $this->refFkValues['notesRelatedByparentId'] = QubitQuery::create();
- }
- else
- {
- $this->refFkValues['notesRelatedByparentId'] =
self::getnotesRelatedByparentIdById($this->id, array('self' => $this) +
$options);
- }
- }
-
- return $this->refFkValues['notesRelatedByparentId'];
- }
-
if ('noteI18ns' == $name)
{
if (!isset($this->refFkValues['noteI18ns']))
@@ -330,46 +275,6 @@
{
}
- if ('ancestors' == $name)
- {
- if (!isset($this->values['ancestors']))
- {
- if ($this->new)
- {
- $this->values['ancestors'] = QubitQuery::create(array('self' =>
$this) + $options);
- }
- else
- {
- $criteria = new Criteria;
- $this->addAncestorsCriteria($criteria);
- $this->addOrderByPreorder($criteria);
- $this->values['ancestors'] = self::get($criteria, array('self' =>
$this) + $options);
- }
- }
-
- return $this->values['ancestors'];
- }
-
- if ('descendants' == $name)
- {
- if (!isset($this->values['descendants']))
- {
- if ($this->new)
- {
- $this->values['descendants'] = QubitQuery::create(array('self' =>
$this) + $options);
- }
- else
- {
- $criteria = new Criteria;
- $this->addDescendantsCriteria($criteria);
- $this->addOrderByPreorder($criteria);
- $this->values['descendants'] = self::get($criteria, array('self' =>
$this) + $options);
- }
- }
-
- return $this->values['descendants'];
- }
-
throw new sfException("Unknown record property \"$name\" on
\"".get_class($this).'"');
}
@@ -559,8 +464,6 @@
protected function insert($connection = null)
{
- $this->updateNestedSet($connection);
-
if (!isset($connection))
{
$connection =
QubitTransactionFilter::getConnection(QubitNote::DATABASE_NAME);
@@ -610,33 +513,6 @@
protected function update($connection = null)
{
- // Update nested set keys only if parent id has changed
- if (isset($this->values['parentId']))
- {
- // Get the "original" parentId before any updates
- $offset = 0;
- $originalParentId = null;
- foreach ($this->tables as $table)
- {
- foreach ($table->getColumns() as $column)
- {
- if ('parentId' == $column->getPhpName())
- {
- $originalParentId = $this->row[$offset];
- break;
- }
- $offset++;
- }
- }
-
- // If updated value of parentId is different then original value,
- // update the nested set
- if ($originalParentId != $this->values['parentId'])
- {
- $this->updateNestedSet($connection);
- }
- }
-
if (!isset($connection))
{
$connection =
QubitTransactionFilter::getConnection(QubitNote::DATABASE_NAME);
@@ -691,9 +567,6 @@
throw new PropelException('This object has already been deleted.');
}
- $this->clear();
- $this->deleteFromNestedSet($connection);
-
$criteria = new Criteria;
$criteria->add(QubitNote::ID, $this->id);
@@ -745,33 +618,6 @@
return $criteria;
}
- public static function addJoinparentCriteria(Criteria $criteria)
- {
- $criteria->addJoin(QubitNote::PARENT_ID, QubitNote::ID);
-
- return $criteria;
- }
-
- public static function addnotesRelatedByparentIdCriteriaById(Criteria
$criteria, $id)
- {
- $criteria->add(QubitNote::PARENT_ID, $id);
-
- return $criteria;
- }
-
- public static function getnotesRelatedByparentIdById($id, array $options =
array())
- {
- $criteria = new Criteria;
- self::addnotesRelatedByparentIdCriteriaById($criteria, $id);
-
- return QubitNote::get($criteria, $options);
- }
-
- public function addnotesRelatedByparentIdCriteria(Criteria $criteria)
- {
- return self::addnotesRelatedByparentIdCriteriaById($criteria, $this->id);
- }
-
public static function addnoteI18nsCriteriaById(Criteria $criteria, $id)
{
$criteria->add(QubitNoteI18n::ID, $id);
@@ -813,140 +659,6 @@
return $noteI18ns[$options['culture']];
}
- public function addAncestorsCriteria(Criteria $criteria)
- {
- return $criteria->add(QubitNote::LFT, $this->lft,
Criteria::LESS_THAN)->add(QubitNote::RGT, $this->rgt, Criteria::GREATER_THAN);
- }
-
- public function addDescendantsCriteria(Criteria $criteria)
- {
- return $criteria->add(QubitNote::LFT, $this->lft,
Criteria::GREATER_THAN)->add(QubitNote::RGT, $this->rgt, Criteria::LESS_THAN);
- }
-
- protected function updateNestedSet($connection = null)
- {
-// HACK Try to prevent modifying left and right values anywhere except in this
-// method. Perhaps it would be more logical to use protected visibility for
-// these values?
-unset($this->values['lft']);
-unset($this->values['rgt']);
- if (!isset($connection))
- {
- $connection =
QubitTransactionFilter::getConnection(QubitNote::DATABASE_NAME);
- }
-
- if (!isset($this->lft) || !isset($this->rgt))
- {
- $delta = 2;
- }
- else
- {
- $delta = $this->rgt - $this->lft + 1;
- }
-
- if (null === $parent = $this->__get('parent', array('connection' =>
$connection)))
- {
- $statement = $connection->prepare('
- SELECT MAX('.QubitNote::RGT.')
- FROM '.QubitNote::TABLE_NAME);
- $statement->execute();
- $row = $statement->fetch();
- $max = $row[0];
-
- if (!isset($this->lft) || !isset($this->rgt))
- {
- $this->lft = $max + 1;
- $this->rgt = $max + 2;
-
- return $this;
- }
-
- $shift = $max + 1 - $this->lft;
- }
- else
- {
- $parent->clear();
-
- if (isset($this->lft) && isset($this->rgt) && $this->lft <= $parent->lft
&& $this->rgt >= $parent->rgt)
- {
- throw new PropelException('An object cannot be a descendant of
itself.');
- }
-
- $statement = $connection->prepare('
- UPDATE '.QubitNote::TABLE_NAME.'
- SET '.QubitNote::LFT.' = '.QubitNote::LFT.' + ?
- WHERE '.QubitNote::LFT.' >= ?');
- $statement->execute(array($delta, $parent->rgt));
-
- $statement = $connection->prepare('
- UPDATE '.QubitNote::TABLE_NAME.'
- SET '.QubitNote::RGT.' = '.QubitNote::RGT.' + ?
- WHERE '.QubitNote::RGT.' >= ?');
- $statement->execute(array($delta, $parent->rgt));
-
- if (!isset($this->lft) || !isset($this->rgt))
- {
- $this->lft = $parent->rgt;
- $this->rgt = $parent->rgt + 1;
- $parent->rgt += 2;
-
- return $this;
- }
-
- if ($this->lft > $parent->rgt)
- {
- $this->lft += $delta;
- $this->rgt += $delta;
- }
-
- $shift = $parent->rgt - $this->lft;
- }
-
- $statement = $connection->prepare('
- UPDATE '.QubitNote::TABLE_NAME.'
- SET '.QubitNote::LFT.' = '.QubitNote::LFT.' + ?, '.QubitNote::RGT.' =
'.QubitNote::RGT.' + ?
- WHERE '.QubitNote::LFT.' >= ?
- AND '.QubitNote::RGT.' <= ?');
- $statement->execute(array($shift, $shift, $this->lft, $this->rgt));
-
- $this->deleteFromNestedSet($connection);
-
- if ($shift > 0)
- {
- $this->lft -= $delta;
- $this->rgt -= $delta;
- }
-
- $this->lft += $shift;
- $this->rgt += $shift;
-
- return $this;
- }
-
- protected function deleteFromNestedSet($connection = null)
- {
- if (!isset($connection))
- {
- $connection =
QubitTransactionFilter::getConnection(QubitNote::DATABASE_NAME);
- }
-
- $delta = $this->rgt - $this->lft + 1;
-
- $statement = $connection->prepare('
- UPDATE '.QubitNote::TABLE_NAME.'
- SET '.QubitNote::LFT.' = '.QubitNote::LFT.' - ?
- WHERE '.QubitNote::LFT.' >= ?');
- $statement->execute(array($delta, $this->rgt));
-
- $statement = $connection->prepare('
- UPDATE '.QubitNote::TABLE_NAME.'
- SET '.QubitNote::RGT.' = '.QubitNote::RGT.' - ?
- WHERE '.QubitNote::RGT.' >= ?');
- $statement->execute(array($delta, $this->rgt));
-
- return $this;
- }
-
public function __call($name, $args)
{
if ('get' == substr($name, 0, 3) || 'set' == substr($name, 0, 3))
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.