Skip to content

Commit

Permalink
Add restriction migration
Browse files Browse the repository at this point in the history
This adds migration for applied locations and items meta (but its untested)
  • Loading branch information
datengraben committed Aug 20, 2023
1 parent 2611930 commit d529725
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Migration/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use CommonsBooking\Wordpress\CustomPostType\Item;
use CommonsBooking\Wordpress\CustomPostType\Location;
use CommonsBooking\Wordpress\CustomPostType\Timeframe;
use CommonsBooking\Wordpress\CustomPostType\CustomPostType;
use Exception;
use WP_Post;
use WP_Query;
Expand Down Expand Up @@ -61,6 +62,11 @@ public static function migrateAll() {
'complete' => 0,
'failed' => 0,
],
'restrictions' => [
'index' => 0,
'complete' => 0,
'failed' => 0,
],
'bookingCodes' => [
'index' => 0,
'complete' => 0,
Expand Down Expand Up @@ -106,6 +112,10 @@ public static function migrateAll() {
'repoFunction' => 'getBookings',
'migrationFunction' => 'migrateBooking',
],
'restrictions' => [
'repoFunction' => 'getRestrictions',
'migrationFunction' => 'migrateRestriction',
],
'bookingCodes' => [
'repoFunction' => 'getBookingCodes',
'migrationFunction' => 'migrateBookingCode',
Expand Down Expand Up @@ -567,6 +577,29 @@ public static function migrateBooking( $booking ): bool {
return self::savePostData( $existingPost, $postData, $postMeta );
}

public static function migrateRestriction( $restriction ): bool {

// Nothing to change for migration
$postData = array();
// Nothing to change for migration
$postMeta = array();

$existingPost = self::getExistingPost( $restriction['id'], \CommonsBooking\Wordpress\CustomPostType\Restriction::$postType );

// Conditionally migrate
$restrictionItems = get_post_meta( $existingPost->ID, \CommonsBooking\Model\Restriction::META_ITEM_ID );
if ( empty( $restrictionItems) ) {
$postMeta[ \CommonsBooking\Model\Restriction::META_ITEM_ID ] = CustomPostType::SELECTION_ALL_POSTS;
}

$restrictionLocations = get_post_meta( $existingPost->ID, \CommonsBooking\Model\Restriction::META_LOCATION_ID );
if ( empty( $restrictionLocations) ) {
$postMeta[ \CommonsBooking\Model\Restriction::META_LOCATION_ID ] = CustomPostType::SELECTION_ALL_POSTS;
}

return self::savePostData( $existingPost, $postData, $postMeta );
}

/**
* Migrates CB1 Booking Code to CB2.
*
Expand Down

2 comments on commit d529725

@chriwen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wozu müssen wir denn Restrictions importieren? Das gabs doch in CB1 garnicht? Außer bei Flotte. Sehe aber eigentlich keine Bedarf das in den Code zu implementieren. Was meint ihr?

@datengraben
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das bezog sich auf den Kommentar von @hansmorb migrate restrictions with all_options not set. Ich dachte es geht um Migrations von Daten für Plugin-Versionen kleiner als die Version, die dann die all_posts Option enthalten wird. Aber die Migration-Klasse (bzw. migrateAll) wird nur Explizit von CB1 auf CB2 aufgerufen? Habe ich jetzt erst gesehen. @chriwen

Please sign in to comment.