Skip to content

Commit 0288029

Browse files
authored
Merge pull request #172 from gigya/develop
6.2.0
2 parents 56cce64 + 4f80ce0 commit 0288029

File tree

12 files changed

+700
-96
lines changed

12 files changed

+700
-96
lines changed

GigyaAction.php

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function __construct() {
8181
add_filter( 'get_avatar', array( $this, 'getGigyaAvatar' ), 10, 5 );
8282
add_filter( 'login_message', 'raas_wp_login_custom_message' );
8383
add_filter( 'cron_schedules', array( $this, 'getOfflineSyncSchedules' ) );
84+
add_action( 'wp_ajax_get_out_of_sync_users', array( $this, 'getOutOfSyncUsers' ) );
85+
add_action( 'get_out_of_sync_users', array( $this, 'getOutOfSyncUsers' ) );
86+
add_action( 'wp_ajax_nopriv_get_out_of_sync_users', array( $this, 'getOutOfSyncUsers' ) );
87+
8488

8589
/* Plugins shortcode activation switches */
8690
require_once GIGYA__PLUGIN_DIR . 'features/gigyaPluginsShortcodes.php';
@@ -203,6 +207,8 @@ public function init()
203207
if ( is_admin() ) {
204208
/* Loads requirements for the admin settings section. */
205209
require_once GIGYA__PLUGIN_DIR . 'admin/admin.GigyaSettings.php';
210+
require_once GIGYA__PLUGIN_DIR . 'admin/features/GigyaReportGenerator.php';
211+
206212
new GigyaSettings;
207213
}
208214
}
@@ -629,6 +635,79 @@ public function ajaxCleanDB() {
629635
}
630636
}
631637

638+
/**
639+
* Get GIGYA__SYNC_REPORT_MAX_USERS from Gigya and check if the users exist at WP DB. and that their UIDs match.
640+
* The same idea with getting the same amount of users from Gigya and searching in WP DB.
641+
* the file will be generated inside GIGYA__USER_FILES folder.
642+
*/
643+
public function getOutOfSyncUsers() {
644+
645+
if ( ! is_dir( GIGYA__USER_FILES ) ) {
646+
$message = "Could not generate report: The path: " . GIGYA__USER_FILES . " does not exist";
647+
error_log( $message );
648+
wp_send_json_error( $message );
649+
650+
return;
651+
};
652+
653+
try {
654+
$wp_to_gigya_compare = GigyaReportGenerator::getWPUsersNotInGigya();
655+
$gigya_to_wp_compare = GigyaReportGenerator::getGigyaUsersNotInWP();
656+
} catch ( GSApiException $e ) {
657+
$message = "There was an error getting the data from SAP servers, callID: " . $e->getCallId() . ', Error Code: ' . $e->getErrorCode();
658+
659+
wp_send_json_error( $message );
660+
error_log( $message );
661+
return;
662+
663+
} catch ( GSException $e ) {
664+
$message = "Could not reach SAP server: " . $e->errorMessage;
665+
666+
wp_send_json_error( $message );
667+
error_log( $message );
668+
return;
669+
}
670+
671+
$message = '';
672+
$files_names = array_keys( array_merge( $wp_to_gigya_compare, $gigya_to_wp_compare ) );
673+
674+
/*generating files for each file_name*/
675+
foreach ( $files_names as $file_name ) {
676+
677+
if ( array_key_exists( $file_name, $wp_to_gigya_compare ) and array_key_exists( $file_name, $gigya_to_wp_compare ) ) {
678+
$merged_array = array_merge( $wp_to_gigya_compare[ $file_name ], $gigya_to_wp_compare[ $file_name ] );
679+
} else if ( array_key_exists( $file_name, $wp_to_gigya_compare ) ) {
680+
$merged_array = $wp_to_gigya_compare[ $file_name ];
681+
} else if ( array_key_exists( $file_name, $gigya_to_wp_compare ) ) {
682+
$merged_array = $gigya_to_wp_compare[ $file_name ];
683+
} else {
684+
$merged_array = array();
685+
}
686+
687+
$file = fopen( GIGYA__USER_FILES . $file_name . '_' . date( "Y-m-d_H-i-s" ) . ".csv", 'w' );
688+
if ( strstr( $file_name, GigyaReportGenerator::$SAP_users_not_existing_in_WP ) !== false ) {
689+
fputcsv( $file, array( 'UID', 'Email' ) );
690+
} else {
691+
fputcsv( $file, array( 'ID', 'Email' ) );
692+
}
693+
if ( ! empty( $merged_array ) ) {
694+
$message .= '<br>* ' . $file_name . '_' . date( "Y-m-d_H-i-s" ) . '.csv';
695+
foreach ( $merged_array as $user ) {
696+
fputcsv( $file, $user );
697+
}
698+
}
699+
fclose( $file );
700+
}
701+
702+
if ( empty( $message ) ) {
703+
$message = 'All ' . number_format( GIGYA__SYNC_REPORT_MAX_USERS ) . ' users that have been checked are in sync.';
704+
} else {
705+
$message = 'The report has been generated successfully and saved to: ' . GIGYA__USER_FILES . '<br> Generated filenames are below. Note, this list does not include empty files. <br>' . $message;
706+
}
707+
708+
wp_send_json_success( $message );
709+
}
710+
632711
/**
633712
* Get WordPress user object by Gigya UID
634713
*
@@ -710,6 +789,7 @@ public function executeOfflineSyncCron() {
710789
$enable_job = $config['map_offline_sync_enable'];
711790
$email_on_success = $config['map_offline_sync_email_on_success'];
712791
$email_on_failure = $config['map_offline_sync_email_on_failure'];
792+
$required_field = 'profile'; /* Offline sync might not work on users without a profile */
713793

714794
$helper = new GigyaOfflineSync();
715795

@@ -723,7 +803,7 @@ public function executeOfflineSyncCron() {
723803
}
724804
$gigya_query .= " ORDER BY lastUpdatedTimestamp ASC LIMIT " . GIGYA__OFFLINE_SYNC_MAX_USERS;
725805
$gigya_cms = new GigyaCMS();
726-
$gigya_users = $gigya_cms->searchGigyaUsers( [ 'query' => $gigya_query ] );
806+
$gigya_users = $gigya_cms->searchGigyaUsers( [ 'query' => $gigya_query ], $required_field );
727807
$processed_users = 0;
728808
$users_not_found = 0;
729809
$uids_not_found = [];

admin/admin.GigyaSettings.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public function __construct() {
3939
*/
4040
public function adminInit() {
4141

42+
$params = array(
43+
'max_execution_time' => intval( ini_get( 'max_execution_time' ) ) * 1000
44+
);
45+
46+
$params = apply_filters( 'gigya_admin_params', $params );
47+
wp_localize_script( 'gigya_admin_js', 'gigyaAdminParams', $params );
48+
4249
// Add settings sections.
4350
foreach ( $this->getSections() as $id => $section ) {
4451
$option_group = $section['slug'] . '-group';

0 commit comments

Comments
 (0)