Skip to content

Commit

Permalink
Merge pull request #189 from RRZE-Webteam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rvdforst authored Feb 7, 2024
2 parents 0dc2d06 + 7d3be7f commit 26f20ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
6 changes: 3 additions & 3 deletions includes/CPT/CalendarFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public static function maybeDelete($newStatus, $oldStatus, $post)
$newStatus != 'publish' && $oldStatus == 'publish'
&& self::POST_TYPE == get_post_type($postId)
) {
self::deleteData($postId);
self::deleteEvent($postId);
}
}

Expand Down Expand Up @@ -495,8 +495,8 @@ private static function saveData($postId)
Events::insertData($postId);
}

private static function deleteData($postId)
private static function deleteEvent($postId)
{
Events::deleteData($postId);
Events::deleteEvent($postId);
}
}
36 changes: 28 additions & 8 deletions includes/ICS/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class Events

public static function updateFeedsItems()
{
self::deleteUnlinkedEvents();

$feeds = self::getFeeds();
foreach ($feeds as $post) {
if ($post->post_status == 'publish') {
self::updateItems($post->ID);
self::insertData($post->ID);
} else {
self::deleteStaleData($post->ID);
self::deleteEvent($post->ID);
}
}
}
Expand Down Expand Up @@ -583,7 +585,7 @@ public static function insertData(int $postId)
$items = count($items) ? self::getListData($postId, $items) : $items;

if (count($items)) {
self::deleteData($postId);
self::deleteEvent($postId);
} else {
return;
}
Expand Down Expand Up @@ -639,12 +641,7 @@ public static function insertData(int $postId)
}
}

private static function deleteStaleData(int $feedId)
{
self::deleteData($feedId);
}

public static function deleteData(int $feedId)
public static function deleteEvent(int $feedId)
{
$metaKey = 'ics_feed_id';
$metaValue = $feedId;
Expand All @@ -666,4 +663,27 @@ public static function deleteData(int $feedId)
wp_reset_postdata();
}
}

public static function deleteUnlinkedEvents()
{
$metaKey = 'ics_feed_id';
$query = new \WP_Query([
'meta_key' => $metaKey,
'post_type' => CalendarEvent::POST_TYPE,
'posts_per_page' => 100
]);

if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$postId = get_the_ID();

$feedId = get_post_meta($postId, $metaKey, true);
if (!get_post($feedId)) {
wp_delete_post($postId, true);
}
}
wp_reset_postdata();
}
}
}
2 changes: 1 addition & 1 deletion rrze-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: RRZE Calendar
Plugin URI: https://github.com/RRZE-Webteam/rrze-calendar
Description: Import and output of FAU public events.
Version: 2.1.0
Version: 2.1.1
Author: RRZE Webteam
Author URI: https://blogs.fau.de/webworking/
License: GNU General Public License v3.0
Expand Down

0 comments on commit 26f20ba

Please sign in to comment.