break; } } } // only try to save base entity if no errors if (!$error) { if ($blog->save()) { // remove sticky form entries elgg_clear_sticky_form('blog'); // remove autosave draft if exists $blog->deleteAnnotations('blog_auto_save'); // no longer a brand new post. $blog->deleteMetadata('new_post'); // if this was an edit, create a revision annotation if (!$new_post && $revision_text) { $blog->annotate('blog_revision', $revision_text); } system_message(elgg_echo('blog:message:saved')); $status = $blog->status; // add to river if changing status or published, regardless of new post // because we remove it for drafts. if (($new_post || $old_status == 'draft') && $status == 'published') { add_to_river('river/object/blog/create', 'create', $blog->owner_guid, $blog->getGUID()); // we only want notifications sent when post published register_notification_object('object', 'blog', elgg_echo('blog:newpost')); elgg_trigger_event('publish', 'object', $blog); // reset the creation time for posts that move from draft to published if ($guid) { $blog->time_created = time(); $blog->save(); }
$error = elgg_echo('blog:error:cannot_save'); } } // creat draft annotation if (!$error) { // annotations don't have a "time_updated" so // we have to delete everything or the times are wrong. // don't save if nothing changed $auto_save_annotations = $blog->getAnnotations(array('annotation_name' => 'blog_auto_save', 'limit' => 1)); if ($auto_save_annotations) { $auto_save = $auto_save_annotations[0]; } else { $auto_save = FALSE; } if (!$auto_save) { $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) { $blog->deleteAnnotations('blog_auto_save'); $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) { // this isn't an error because we have an up to date annotation. $annotation_id = $auto_save->id; } if (!$annotation_id) { $error = elgg_echo('blog:error:cannot_auto_save'); } } } else { $error = elgg_echo('blog:error:missing:description'); } if ($error) {