To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit b012eabc authored by vermeul's avatar vermeul
Browse files

merge

parent 087c956d
...@@ -391,18 +391,17 @@ EOT; ...@@ -391,18 +391,17 @@ EOT;
} }
} }
/** /*
* This function is called after the save page request has been processed. This function is called after the save page request has been processed.
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentSaveComplete @see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentSaveComplete
*
* save all new or updated annotations. Annotations which are save all new or updated annotations. Annotations which are
* no longer present are being deleted. no longer present are being deleted.
*/ */
public static function onPageContentSaveComplete($wikiPage, $user, $content, $summary, public static function onPageContentSaveComplete($wikiPage, $user, $content, $summary,
$isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) { $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) {
$status->fatal("lksjdfljsdl");
$dbw = wfGetDB( DB_MASTER ); $dbw = wfGetDB( DB_MASTER );
$seen_bookmarks = array(); $seen_ids = array();
foreach ( self::$annotations as $bookmark => $annotation ){ foreach ( self::$annotations as $bookmark => $annotation ){
$annotation_id = 0; $annotation_id = 0;
...@@ -446,6 +445,7 @@ EOT; ...@@ -446,6 +445,7 @@ EOT;
); );
$annotation_id = $dbw->insertId(); $annotation_id = $dbw->insertId();
} }
array_push($seen_ids, $annotation_id);
# insert / update the annotation categories # insert / update the annotation categories
if ( $annotation['categories'] ) { if ( $annotation['categories'] ) {
...@@ -459,15 +459,15 @@ EOT; ...@@ -459,15 +459,15 @@ EOT;
} }
# delete all annotation categories which are no longer assigned # delete all annotation categories which are no longer assigned
# to this annotation # to this annotation
$dbw->delete( $dbw->delete(
'yata_annotation_category', 'yata_annotation_category',
array( array(
page_id => $wikiPage->getId(), page_id => $wikiPage->getId(),
annotation_id => $annotation_id, annotation_id => $annotation_id,
'category_id NOT IN(' .$dbw->makeList($seen_acs). ')' 'category_id NOT IN(' .$dbw->makeList($seen_acs). ')'
) )
); );
} }
else { else {
# delete all existing annotation categories, # delete all existing annotation categories,
# since no category is assigned anymore # since no category is assigned anymore
...@@ -479,14 +479,14 @@ EOT; ...@@ -479,14 +479,14 @@ EOT;
) )
); );
} }
$seen_bookmarks[] = $bookmark;
} }
$where = array(); $where = [
$where["page_id"] = $wikiPage->getId(); "page_id" => $wikiPage->getId()
if ($seen_bookmarks) { ];
$where[] = 'bookmark NOT IN(' .$dbw->makeList($seen_bookmarks). ')';
if ($seen_ids) {
$where[] = 'id NOT IN(' .$dbw->makeList($seen_ids). ')';
} }
# find all all annotations which are no longer present # find all all annotations which are no longer present
...@@ -495,27 +495,40 @@ EOT; ...@@ -495,27 +495,40 @@ EOT;
array( 'id' ), array( 'id' ),
$where $where
); );
# delete all annotations which are no longer present # delete all annotations which are no longer present
foreach( $annotations_to_delete as $annotation) { foreach( $annotations_to_delete as $annotation) {
$dbw->delete( try {
'yata_annotation', $dbw->delete(
array( 'yata_annotation',
id => $annotation->id array(
) 'id' => $annotation->id
); )
} );
}
# delete all annotation categories catch (Exception $e) {
# of these to-be-deleted annotations print($e->getMessage());
foreach( $annotations_to_delete as $annotation) { die;
$dbw->delete( }
'yata_annotation_category',
array( # delete all categories assigned to annotations
id => $annotation->id # which do not exist anymore
)
); $delete_where = [
page_id => $wikiPage->getId(),
annotation_id => $annotation->id
];
try {
$dbw->delete(
'yata_annotation_category',
$delete_where
);
}
catch (Exception $e) {
print($e->getMessage());
die;
}
} }
} }
...@@ -912,7 +925,7 @@ EOT; ...@@ -912,7 +925,7 @@ EOT;
1. get all existing annotations which exist on that page. 1. get all existing annotations which exist on that page.
2. find out which annotations have been updated (using the unique identifier) 2. find out which annotations have been updated (using the unique identifier)
3. find out which annotations have been added -> assign a unique identifier 3. find out which annotations have been added -> assign a unique identifier
4. find out which annotations have been removed from the wikitext and delete them 4. find out which annotations have been removed from the wikitext and delete them
5. assign every annotation to one or more categories 5. assign every annotation to one or more categories
6. assign every annotation to this page 6. assign every annotation to this page
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment