| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | public function __construct( $core ) { |
| 21 | 21 | parent::__construct( $core ); |
| 22 | 22 | |
| 23 | 23 | // In case the software has never been synchronized, force it. |
| 24 | - if ( ! get_option( 'patchstack_software_data_hash', false ) ) { | |
| 24 | + if ( ! get_option( 'patchstack_software_data_hash', false ) && ! get_option( 'patchstack_software_upload_attempted', false )) { | |
| 25 | 25 | $this->upload_software(); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // Register the actions. |
| @@ -49,11 +49,14 @@ | ||
| 49 | 49 | $data = $this->get_software_data(); |
| 50 | 50 | $hash = sha1( json_encode( $data ) ); |
| 51 | 51 | |
| 52 | 52 | // Do not sync for no reason. |
| 53 | - if ( ! defined( 'DOING_CRON' ) && ! isset( $_POST['webarx_secret'] ) && get_option( 'patchstack_software_data_hash', false ) === $hash && ! is_admin() ) { | |
| 53 | + if ( ! defined( 'DOING_CRON' ) && ! isset( $_POST['webarx_secret'] ) && get_option( 'patchstack_software_data_hash', false ) === $hash && ! is_admin() && ! defined( 'WP_CLI ' ) ) { | |
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | + | |
| 57 | + // Make sure to not keep calling this function. | |
| 58 | + update_option( 'patchstack_software_upload_attempted', true ); | |
| 56 | 59 | |
| 57 | 60 | // Synchronize the software list with the API. |
| 58 | 61 | $results = $this->plugin->api->upload_software( [ 'software' => json_encode( $data ) ] ); |
| 59 | 62 | if ( isset( $results['success'] ) ) { |