Index: trunk/core/units/themes/themes_eh.php =================================================================== diff -u -r8069 -r8075 --- trunk/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 8069) +++ trunk/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 8075) @@ -16,23 +16,44 @@ $ids = $this->StoreSelectedIDs($event); if ($ids) { $id = array_shift($ids); - - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - - $sql = 'UPDATE '.$table_name.' - SET PrimaryTheme = 0'; - $this->Conn->Query($sql); - - - $sql = 'UPDATE '.$table_name.' - SET PrimaryTheme = 1, Enabled = 1 - WHERE '.$id_field.' = '.$id; - $this->Conn->Query($sql); + $this->setPrimary($id); } $this->clearSelectedIDs($event); } + + function setPrimary($id) + { + $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + + $sql = 'UPDATE '.$table_name.' + SET PrimaryTheme = 0'; + $this->Conn->Query($sql); + + + $sql = 'UPDATE '.$table_name.' + SET PrimaryTheme = 1, Enabled = 1 + WHERE '.$id_field.' = '.$id; + $this->Conn->Query($sql); + } + + /** + * Set correct parent path for newly created categories + * + * @param kEvent $event + */ + function OnAfterCopyToLive(&$event) + { + $object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true, 'live_table' => true)); + /* @var $object kDBItem */ + + $object->Load($event->getEventParam('id')); + + if ($object->GetDBField('PrimaryTheme')) { + $this->setPrimary($event->getEventParam('id')); + } + } } ?> \ No newline at end of file