Index: branches/5.2.x/core/units/content/content_eh.php =================================================================== diff -u -N -r16339 -r16409 --- branches/5.2.x/core/units/content/content_eh.php (.../content_eh.php) (revision 16339) +++ branches/5.2.x/core/units/content/content_eh.php (.../content_eh.php) (revision 16409) @@ -1,6 +1,6 @@ Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; - return ; + + return; } - if ( !$this->saveContentBlock($event, false) ) { + $updated = $this->saveContentBlock($event, false); + + if ( $this->Application->GetVar('ajax') == 'yes' ) { + $event->status = kEvent::erSTOP; + echo ($updated === false) ? 'FAILED' : 'OK'; + } + elseif ( !$updated ) { $event->status = kEvent::erFAIL; } @@ -133,16 +140,15 @@ */ function saveContentBlock($event, $is_draft) { - $object = $event->getObject( Array('skip_autoload' => true) ); - /* @var $object kDBItem */ + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); if ( !$items_info ) { return ''; } list ($object, $revision) = $this->getContentBlockAndRevision($event); /* @var $revision kDBItem */ + /* @var $object kDBItem */ list (, $field_values) = each($items_info); $object->SetFieldsFromHash($field_values); @@ -151,17 +157,17 @@ if ( $updated ) { $revision->SetDBField('AutoSavedOn_date', adodb_mktime()); - $revision->SetDBField('AutoSavedOn_time', adodb_mktime()); - $revision->Update(); + $revision->SetDBField('AutoSavedOn_time', adodb_mktime()); + $revision->Update(); } if ( $is_draft ) { if ( $updated ) { - $page_helper = $this->Application->recallObject('PageHelper'); - /* @var $page_helper PageHelper */ + $page_helper = $this->Application->recallObject('PageHelper'); + /* @var $page_helper PageHelper */ - return $revision->GetField('AutoSavedOn') . ' (' . $page_helper->getAgoTime( $revision->GetDBField('AutoSavedOn') ) . ')'; - } + return $revision->GetField('AutoSavedOn') . ' (' . $page_helper->getAgoTime($revision->GetDBField('AutoSavedOn')) . ')'; + } } else { return $updated; @@ -180,20 +186,20 @@ $event->status = kEvent::erSTOP; if ( $this->Application->GetVar('ajax') != 'yes' ) { - return ; + return; } - list ($object, $revision) = $this->getContentBlockAndRevision($event); + list (, $revision) = $this->getContentBlockAndRevision($event); /* @var $revision kDBItem */ $page_helper = $this->Application->recallObject('PageHelper'); - /* @var $page_helper PageHelper */ + /* @var $page_helper PageHelper */ - $time = $revision->GetField('AutoSavedOn'); + $time = $revision->GetField('AutoSavedOn'); - if ( $time ) { - echo $time . ' (' . $page_helper->getAgoTime( $revision->GetDBField('AutoSavedOn') ) . ')'; - } + if ( $time ) { + echo $time . ' (' . $page_helper->getAgoTime($revision->GetDBField('AutoSavedOn')) . ')'; + } } /** @@ -204,7 +210,7 @@ */ function loadFromRevision(&$object, &$revision) { - $load_keys = Array ( + $load_keys = Array( 'PageId' => $object->GetDBField('PageId'), 'ContentNum' => $object->GetDBField('ContentNum'), 'RevisionId' => $revision->GetID(), @@ -213,27 +219,34 @@ $object->Load($load_keys); } + /** + * Returns content block. + * + * @param kEvent $event + * + * @return kDBItem[] + */ function getContentBlockAndRevision($event) { - $object = $event->getObject( Array('skip_autoload' => true) ); + $object = $event->getObject(Array('skip_autoload' => true)); /* @var $object kDBItem */ - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); if ( !$items_info ) { - return ; + return array(); } - list ($id, $field_values) = each($items_info); + list ($id,) = each($items_info); $object->Load($id); - $revision = $this->Application->recallObject('page-revision', null, Array ('skip_autoload' => true)); + $revision = $this->Application->recallObject('page-revision', null, Array('skip_autoload' => true)); /* @var $revision kDBItem */ - $revision->Load( $object->GetDBField('RevisionId') ); + $revision->Load($object->GetDBField('RevisionId')); if ( $this->Application->ConfigValue('EnablePageContentRevisionControl') && !$revision->GetDBField('IsDraft') ) { // editing live revision of a page's content block -> get draft for current user and page - $load_keys = Array ( + $load_keys = Array( 'PageId' => $revision->GetDBField('PageId'), 'IsDraft' => 1, 'CreatedById' => $this->Application->RecallVar('user_id'), @@ -256,6 +269,6 @@ } } - return Array (&$object, &$revision); + return Array(&$object, &$revision); } }