-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActivityPub: Sprint 2 #3216
Draft
mediaformat
wants to merge
4
commits into
idno:dev
Choose a base branch
from
mediaformat:activitypub/sprint-2
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
ActivityPub: Sprint 2 #3216
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/** | ||
* Annotation class | ||
* | ||
* This extends the Entity class to be an | ||
* object in the idno system | ||
* | ||
* @package idno | ||
* @subpackage core | ||
*/ | ||
|
||
namespace Idno\Entities { | ||
|
||
use Idno\Core\Idno; | ||
use Idno\Common\Entity; | ||
use Idno\Common\EntityInterface; | ||
use Idno\Entities\User; | ||
|
||
abstract class Annotation extends Entity implements EntityInterface | ||
{ | ||
// Which collection should this be stored in? | ||
private $collection = 'annotations'; | ||
static $retrieve_collection = 'annotations'; | ||
|
||
|
||
/** | ||
* Retrieve a single record by its UUID | ||
* @param string $uuid | ||
* @param bool $cached Retrieve a cached version if one exists. | ||
* @return bool|Entity | ||
*/ | ||
|
||
static function getByUUID($uuid, $cached = true) | ||
{ | ||
if (!empty(self::$entity_cache[$uuid]) && $cached) return self::$entity_cache[$uuid]; | ||
$return = static::getOneFromAll(array('uuid' => $uuid)); | ||
if ($return instanceof Entity) self::$entity_cache[$uuid] = $return; | ||
return $return; | ||
} | ||
|
||
/** | ||
* Retrieve a single record with certain characteristics, using | ||
* the database getObjects call. | ||
* | ||
* @param array $search List of filter terms (default: none) | ||
* @param array $fields List of fields to return (default: all) | ||
* @return Entity | ||
*/ | ||
|
||
static function getOneFromAll($search = array(), $fields = array()) | ||
{ | ||
if ($records = static::getFromAll($search, $fields, 1)) { | ||
foreach ($records as $record) | ||
return $record; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Simple method to get objects of ANY class in reverse | ||
* chronological order, using the database getObjects call. | ||
* | ||
* @param array $search List of filter terms (default: none) | ||
* @param array $fields List of fields to return (default: all) | ||
* @param int $limit Number of items to return (default: 10) | ||
* @param int $offset Number of items to skip (default: 0 | ||
* @return array | ||
*/ | ||
static function getFromAll($search = array(), $fields = array(), $limit = 10, $offset = 0) | ||
{ | ||
$result = static::getFromX(get_called_class(), $search, $fields, $limit, $offset); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Simple method to get objects of a specified class or classes | ||
* in reverse chronological order, using the database getObjects call. | ||
* | ||
* @param string|array $class Class name(s) to check in (blank string, null or false for all) | ||
* @param array $search List of filter terms (default: none) | ||
* @param array $fields List of fields to return (default: all) | ||
* @param int $limit Number of items to return (default: 10) | ||
* @param int $offset Number of items to skip (default: 0) | ||
* @param array $readGroups Which ACL groups should we check? (default: everything the user can see) | ||
* @return array | ||
*/ | ||
static function getFromX($class, $search = array(), $fields = array(), $limit = 10, $offset = 0, $readGroups = []) | ||
{ | ||
$result = \Idno\Core\Idno::site()->db()->getObject($search['uuid'], static::$retrieve_collection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result here is a different object than was previously received, notably missing are the I think it would make sense to use |
||
if (is_array($result)) $result = array_filter($result); | ||
|
||
return $result; | ||
} | ||
} | ||
|
||
} |
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,214 @@ | ||
-- migrate_annotations() | ||
-- move to /warmup/schemas/{date}.sql when ready | ||
DELIMITER // | ||
|
||
CREATE PROCEDURE migrate_annotations() | ||
BEGIN | ||
DECLARE row_iterator INT; | ||
SET row_iterator = 0; | ||
SELECT | ||
@total_entities_count := COUNT(*) | ||
FROM `entities` | ||
WHERE JSON_CONTAINS_PATH( | ||
JSON_UNQUOTE(`contents`), | ||
'all', | ||
"$.annotations" | ||
); | ||
WHILE row_iterator < @total_entities_count DO | ||
SELECT | ||
@_id := _id, | ||
@uuid := uuid, | ||
@siteid := siteid, | ||
@siteurl := SUBSTRING_INDEX(uuid, 'view', 1) as 'siteurl' | ||
FROM `entities` | ||
WHERE JSON_CONTAINS_PATH( | ||
JSON_UNQUOTE(`contents`), | ||
'all', | ||
"$.annotations" | ||
) | ||
LIMIT row_iterator,1 | ||
; | ||
|
||
SELECT @total_types_count := COUNT( | ||
JSON_KEYS( | ||
JSON_UNQUOTE(`contents`), | ||
"$.annotations" | ||
) | ||
) | ||
FROM `entities` | ||
WHERE `_id` = @_id | ||
; | ||
|
||
SET @annotation_type_iterator = 0; | ||
WHILE @annotation_type_iterator < @total_types_count DO | ||
|
||
SELECT @annotation_type := | ||
JSON_EXTRACT( | ||
JSON_KEYS( | ||
JSON_UNQUOTE(`contents`), | ||
"$.annotations" | ||
), | ||
CONCAT('$[', JSON_UNQUOTE(@annotation_type_iterator), ']') -- gets type from array position | ||
) | ||
FROM `entities` | ||
WHERE `_id` = @_id | ||
; | ||
SELECT @annotations_per_type_count := | ||
JSON_LENGTH( | ||
JSON_KEYS( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '') | ||
) | ||
) | ||
FROM `entities` | ||
WHERE `_id` = @_id | ||
; | ||
|
||
SET @annotations_iterator = 0; | ||
WHILE @annotations_iterator < @annotations_per_type_count DO | ||
|
||
SELECT @annotation_key_id := | ||
JSON_EXTRACT( | ||
JSON_KEYS( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type) | ||
), | ||
CONCAT('$[', JSON_UNQUOTE(@annotations_iterator), ']') | ||
) | ||
FROM `entities` | ||
WHERE `_id` = @_id | ||
; | ||
|
||
SELECT | ||
@annotation_id := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.permalink') | ||
), | ||
@owner_url := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.owner_url') | ||
), | ||
@owner_name := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.owner_name') | ||
), | ||
@owner_image := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.owner_image') | ||
), | ||
@annotation_content := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.content') | ||
), | ||
@annotation_time := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.time') | ||
), | ||
@annotation_title := | ||
JSON_EXTRACT( | ||
JSON_UNQUOTE(`contents`), | ||
CONCAT('$.annotations.', @annotation_type, '.', @annotation_key_id, '.title') | ||
) | ||
FROM `entities` | ||
WHERE `_id` = @_id | ||
; | ||
|
||
if exists ( | ||
SELECT | ||
* | ||
FROM `entities` | ||
WHERE | ||
`entity_subtype` = 'Idno\\Entities\\User' | ||
AND | ||
`siteid` <=> JSON_UNQUOTE(@siteid) | ||
AND | ||
JSON_UNQUOTE(JSON_EXTRACT(JSON_UNQUOTE(`contents`), "$.handle")) = JSON_UNQUOTE(SUBSTRING_INDEX(JSON_UNQUOTE(@owner_url), 'profile/', -1)) | ||
) then | ||
SELECT | ||
@annotation_author := uuid | ||
FROM `entities` | ||
WHERE | ||
`entity_subtype` = 'Idno\\Entities\\User' | ||
AND | ||
`siteid` <=> JSON_UNQUOTE(@siteid) | ||
AND | ||
JSON_UNQUOTE(JSON_EXTRACT(JSON_UNQUOTE(`contents`), "$.handle")) = JSON_UNQUOTE(SUBSTRING_INDEX(JSON_UNQUOTE(@owner_url), 'profile/', -1)) | ||
LIMIT 1 | ||
; | ||
elseif exists ( | ||
SELECT | ||
* | ||
FROM `entities` | ||
WHERE | ||
`entity_subtype` = 'Idno\\Entities\\User' | ||
AND | ||
`siteid` <=> JSON_UNQUOTE(@siteid) | ||
AND | ||
JSON_UNQUOTE(JSON_EXTRACT(JSON_UNQUOTE(`contents`), "$.owner_url")) = JSON_UNQUOTE(@owner_url) | ||
) then | ||
SELECT | ||
@annotation_author := uuid | ||
FROM `entities` | ||
WHERE | ||
`entity_subtype` = 'Idno\\Entities\\User' | ||
AND | ||
`siteid` <=> JSON_UNQUOTE(@siteid) | ||
AND | ||
JSON_UNQUOTE(JSON_EXTRACT(JSON_UNQUOTE(`contents`), "$.owner_url")) = JSON_UNQUOTE(@owner_url) | ||
LIMIT 1 | ||
; | ||
else | ||
INSERT INTO `entities` (uuid, _id, siteid, owner, entity_subtype, contents) | ||
SELECT | ||
@annotation_author := CONCAT(JSON_UNQUOTE(@siteurl),'view/',UUID()) AS uuid, | ||
UUID() AS _id, | ||
JSON_UNQUOTE(@siteid) AS siteid, | ||
'' AS owner, | ||
JSON_UNQUOTE('Idno\\Entities\\User') AS entity_subtype, | ||
JSON_OBJECT( | ||
'owner_name', JSON_UNQUOTE(@owner_name), | ||
'owner_url', JSON_UNQUOTE(@owner_url), | ||
'owner_icon', JSON_UNQUOTE(@owner_image) | ||
) AS contents | ||
; | ||
end if; | ||
|
||
INSERT INTO `annotations` (uuid, _id, siteid, owner, entity_subtype, created, contents, entity_id) | ||
VALUES( | ||
JSON_UNQUOTE(@annotation_key_id), | ||
SUBSTR(JSON_UNQUOTE(@annotation_key_id), -32), | ||
JSON_UNQUOTE(@siteid), | ||
@annotation_author, | ||
CONCAT('Idno\\Annotations\\',UCASE(LEFT(JSON_UNQUOTE(@annotation_type), 1)),SUBSTRING(JSON_UNQUOTE(@annotation_type), 2)), | ||
FROM_UNIXTIME(@annotation_time), | ||
JSON_OBJECT( | ||
'permalink', JSON_UNQUOTE(@annotation_id), | ||
'content', JSON_UNQUOTE(@annotation_content), | ||
'time', JSON_UNQUOTE(@annotation_time), | ||
'title', JSON_UNQUOTE(@annotation_title), | ||
'owner', JSON_UNQUOTE(@annotation_author) | ||
), | ||
JSON_UNQUOTE(@uuid) | ||
); | ||
|
||
SET @annotations_iterator = @annotations_iterator + 1; | ||
END WHILE; | ||
SET @annotation_type_iterator = @annotation_type_iterator + 1; | ||
END WHILE; | ||
-- UPDATE `entities` | ||
-- SET `contents` = JSON_REMOVE( | ||
-- JSON_UNQUOTE(`contents`), | ||
-- "$.annotations" | ||
-- ) | ||
-- WHERE `_id` = @_id; | ||
SET row_iterator = row_iterator + 1; | ||
END WHILE; | ||
END // | ||
|
||
DELIMITER ; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overriding the internals here allow us to keep using the same
getAnnotation()
calls used in templates.