Skip to content
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

Molongui authorship to CAP improvements #420

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Prev Previous commit
Fix saving postmeta
iuravic committed Jan 31, 2024
commit 43a90e0b31b418f0903a81c441da01b5f437ffb0
11 changes: 9 additions & 2 deletions src/Command/General/MolonguiAutorship.php
Original file line number Diff line number Diff line change
@@ -190,6 +190,7 @@ public function cmd_molongui_to_cap( array $pos_args, array $assoc_args ): void
/**
* Create a CAP GA.
*/
$cap_id = null;
if ( $dry_run ) {
$cap_id = 'n/a';
$dry_run_mologui_to_gas[ $molongui_author_value ] = $cap_args['display_name'];
@@ -201,8 +202,14 @@ public function cmd_molongui_to_cap( array $pos_args, array $assoc_args ): void
continue;
}

// Save custom postmeta to GA saying which Molongui user this was.
update_post_meta( $cap_id, self::POSTMETA_ORIGINAL_MOLOGUI_USER, $molongui_author_value );
/**
* Save custom postmeta to GA saying which Molongui user this was.
* Since there could be multiple Molongui users pointing to the same CAP GA, multiple metas are allowed.
*/
$meta_exists = $wpdb->get_var( $wpdb->prepare( "select post_id from {$wpdb->postmeta} where post_id = %d and meta_key = %s and meta_value = %s;", $cap_id, self::POSTMETA_ORIGINAL_MOLOGUI_USER, $molongui_author_value ) );
if ( ! $meta_exists ) {
add_post_meta( $cap_id, self::POSTMETA_ORIGINAL_MOLOGUI_USER, $molongui_author_value );
}
}

$this->log( $dry_run, self::LOG, sprintf( "Created/fetched GA ID %s '%s' from '%s'", $cap_id, $cap_args['display_name'], $molongui_author_value ), Logger::SUCCESS );