Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r8428 -r8432 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8428) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8432) @@ -1842,8 +1842,8 @@ */ function OnUpdate(&$event) { - $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($this->Application->IsAdmin() || !$use_pending_editing) { + $use_pending = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); + if ($this->Application->IsAdmin() || !$use_pending) { parent::OnUpdate($event); return ; } @@ -1861,40 +1861,49 @@ foreach ($items_info as $id => $field_values) { $object->Load($id); - $object->SetFieldsFromHash($field_values); + $edit_perm = $perm_helper->ModifyCheckPermission($object->GetDBField('CreatedById'), $object->GetDBField('CategoryId'), $event->Prefix); - if ($use_pending_editing && !$object->GetDBField('OrgId')) { - // PENDING EDITING enabled & not previously edited -> clone item & change cloned item instead - if ($perm_helper->ModifyCheckPermission($object->GetDBField('CreatedById'), $object->GetDBField('CategoryId'), $event->Prefix) == 2) { - // 1. clone original item - $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($object->GetID()), null, null, null, true); + if ($use_pending && !$object->GetDBField('OrgId') && ($edit_perm == STATUS_PENDING)) { + // pending editing enabled + not pending copy -> get/create pending copy & save changes to it + $original_id = $object->GetID(); + $original_resource_id = $object->GetDBField('ResourceId'); - $original_id = $object->GetID(); - $original_resource_id = $object->GetDBField('ResourceId'); - $ci_table = $this->Application->getUnitOption('ci', 'TableName'); - - // 2. apply all operations to cloned item + $object->Load($original_id, 'OrgId'); + if (!$object->isLoaded()) { + // 1. user has no pending copy of live item -> clone live item + $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($original_id), null, null, null, true); $object->Load($cloned_ids[0]); $object->SetFieldsFromHash($field_values); - // 2. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem + // 1a. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem + $ci_table = $this->Application->getUnitOption('ci', 'TableName'); $sql = 'DELETE FROM '.$ci_table.' WHERE ItemResourceId = '.$object->GetDBField('ResourceId').' AND PrimaryCat = 1'; $this->Conn->Query($sql); - // 3. copy main item categoryitems to cloned item + // 1b. copy main item categoryitems to cloned item $sql = 'INSERT INTO '.$ci_table.' (CategoryId, ItemResourceId, PrimaryCat, ItemPrefix, Filename) SELECT CategoryId, '.$object->GetDBField('ResourceId').' AS ItemResourceId, PrimaryCat, ItemPrefix, Filename FROM '.$ci_table.' WHERE ItemResourceId = '.$original_resource_id; $this->Conn->Query($sql); - // 4. put cloned id to OrgId field of item being cloned + // 1c. put cloned id to OrgId field of item being cloned $object->SetDBField('Status', STATUS_PENDING_EDITING); $object->SetDBField('OrgId', $original_id); - $this->Application->SetVar($event->getPrefixSpecial().'_id', $object->GetID()); } + else { + // 2. user has pending copy of live item -> just update field values + $object->SetFieldsFromHash($field_values); + } + + // update id in request (used for redirect in mod-rewrite mode) + $this->Application->SetVar($event->getPrefixSpecial().'_id', $object->GetID()); } + else { + // 3. already editing pending copy -> just update field values + $object->SetFieldsFromHash($field_values); + } if ($object->Update()) { $event->status = erSUCCESS;