-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Elgg#2146 Migrate comment annotations to ElggComment objects.
- Loading branch information
Showing
23 changed files
with
330 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
<?php | ||
/** | ||
* Elgg delete comment action | ||
* Delete comment entity | ||
* | ||
* @package Elgg | ||
* @package Elgg.Core | ||
* @subpackage Comments | ||
*/ | ||
|
||
// Make sure we can get the comment in question | ||
$annotation_id = (int) get_input('annotation_id'); | ||
$comment = elgg_get_annotation_from_id($annotation_id); | ||
if ($comment && $comment->canEdit()) { | ||
$comment->delete(); | ||
system_message(elgg_echo("generic_comment:deleted")); | ||
$comment_guid = get_input('guid'); | ||
$comment = get_entity($comment_guid); | ||
|
||
if (elgg_instanceof($comment, 'object', 'comment') && $comment->canEdit()) { | ||
if ($comment->delete()) { | ||
system_message(elgg_echo('generic_comment:deleted')); | ||
} else { | ||
register_error(elgg_echo('generic_comment:notdeleted')); | ||
} | ||
} else { | ||
register_error(elgg_echo("generic_comment:notdeleted")); | ||
register_error(elgg_echo('generic_comment:notfound')); | ||
} | ||
|
||
forward(REFERER); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* ElggComment | ||
* | ||
* @package Elgg.Core | ||
* @subpackage Comments | ||
* @since 1.9.0 | ||
*/ | ||
class ElggComment extends ElggObject { | ||
|
||
/** @override */ | ||
protected function initializeAttributes() { | ||
parent::initializeAttributes(); | ||
|
||
$this->attributes['subtype'] = "comment"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Elgg comments | ||
* | ||
* @package Elgg.Core | ||
* @subpackage Comments | ||
* @since 1.9 | ||
*/ | ||
|
||
/** | ||
* Comments initialisation function | ||
* | ||
* @return void | ||
* @access private | ||
*/ | ||
function comments_init() { | ||
// Register entity type | ||
elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_comment_setup_entity_menu', 900); | ||
|
||
elgg_register_entity_url_handler('object', 'comment', 'comments_url_handler'); | ||
} | ||
|
||
/** | ||
* Setup the menu shown with a comment | ||
* | ||
* @return array | ||
*/ | ||
function elgg_comment_setup_entity_menu($hook, $type, $return, $params) { | ||
if (elgg_in_context('widgets')) { | ||
return $return; | ||
} | ||
|
||
$entity = $params['entity']; | ||
if (!elgg_instanceof($entity, 'object', 'comment')) { | ||
return $return; | ||
} | ||
|
||
// Remove edit link and access level from the menu | ||
foreach($return as $key => $item) { | ||
if (in_array($item->getName(), array('access', 'edit'))) { | ||
unset($return[$key]); | ||
} | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
/** | ||
* Allow users to comment entities not owned by them. | ||
* | ||
* Object being commented is used as the container of the comment so | ||
* permission check must be overridden if user isn't the owner of the object. | ||
* | ||
* @todo Is this the correct way? | ||
*/ | ||
function comments_container_permissions_override ($hook, $type, $return, $params) { | ||
if ($params['subtype'] === 'comment') { | ||
return true; | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
/** | ||
* Format and return the URL for comments. | ||
* | ||
* The url consists of container's url and comment's anchor. | ||
* | ||
* @param ElggObject $entity Comment object | ||
* @return string URL of comment. | ||
*/ | ||
function comments_url_handler($entity) { | ||
if (!$entity->getOwnerEntity()) { | ||
// default to a standard view if no owner. | ||
return FALSE; | ||
} | ||
|
||
$container_url = $entity->getContainerEntity()->getURL(); | ||
|
||
$comment_anchor = "comment-{$entity->getGUID()}"; | ||
|
||
return "$container_url#$comment_anchor"; | ||
} | ||
|
||
elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'comments_container_permissions_override'); | ||
|
||
elgg_register_event_handler('init', 'system', 'comments_init', 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
engine/lib/upgrades/2013010400-1.9.0_dev-comments_to_entities-faba94768b055b08.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Elgg 1.9.0-dev upgrade 2013010400 | ||
* comments_to_entities | ||
* | ||
* Convert comment annotations to entities | ||
*/ | ||
|
||
// Register subtype and class for comments | ||
update_subtype('object', 'comment', 'ElggComment'); | ||
|
||
// Before 1.9 there was no option for disabling comments so enable them by default | ||
set_config('comments_enabled', TRUE); | ||
|
||
$ia = elgg_set_ignore_access(true); | ||
$batch = new ElggBatch('elgg_get_annotations', array( | ||
'annotation_names' => 'generic_comment', | ||
'limit' => false, | ||
)); | ||
$batch->setIncrementOffset(false); | ||
|
||
$db_prefix = elgg_get_config('dbprefix'); | ||
|
||
// Create a new object for each annotation | ||
foreach ($batch as $annotation) { | ||
$object = new ElggComment(); | ||
$object->owner_guid = $annotation->owner_guid; | ||
$object->container_guid = $annotation->entity_guid; | ||
$object->description = $annotation->value; | ||
$object->access_id = $annotation->access_id; | ||
$object->save(); | ||
|
||
// We need to save once before setting time_created | ||
$object->time_created = $annotation->time_created; | ||
$object->save(); | ||
|
||
$guid = $object->getGUID(); | ||
|
||
/** | ||
* Update the entry in river table for this comment | ||
* | ||
* - Update the view path | ||
* - Remove annotation id | ||
* - Save comment guid to the target_guid column | ||
*/ | ||
$query = "UPDATE {$db_prefix}river | ||
SET view='river/object/comment/create', annotation_id=0, target_guid=$guid | ||
WHERE action_type='comment' AND annotation_id={$annotation->id}"; | ||
update_data($query); | ||
|
||
// Delete the annotation | ||
$annotation->delete(); | ||
} | ||
elgg_set_ignore_access($ia); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.