@@ -2,10 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace EventEspressoBatchRequest\JobHandlers; |
| 4 | 4 | |
| 5 | -use EEM_Event; |
|
| 6 | -use EEM_Price; |
|
| 7 | -use EEM_Ticket; |
|
| 8 | -use EventEspresso\core\exceptions\InvalidClassException; |
|
| 9 | 5 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 10 | 6 | use EventEspresso\core\services\orm\tree_traversal\ModelObjNode; |
| 11 | 7 | use EventEspressoBatchRequest\Helpers\BatchRequestException; |
@@ -27,122 +27,122 @@ |
||
| 27 | 27 | { |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - * @param JobParameters $job_parameters |
|
| 33 | - * @throws BatchRequestException |
|
| 34 | - * @return JobStepResponse |
|
| 35 | - */ |
|
| 36 | - public function create_job(JobParameters $job_parameters) |
|
| 37 | - { |
|
| 38 | - $deletion_job_code = $job_parameters->request_datum('deletion_job_code', array()); |
|
| 39 | - $roots = get_option('EEBatchDeletion' . $deletion_job_code, null); |
|
| 40 | - if($roots === null){ |
|
| 41 | - throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
| 42 | - } |
|
| 43 | - $ids_to_delete = []; |
|
| 44 | - foreach ($roots as $root) { |
|
| 45 | - if(! $root instanceof ModelObjNode){ |
|
| 46 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
| 47 | - } |
|
| 48 | - $ids_to_delete = array_replace_recursive($ids_to_delete, $root->getIds()); |
|
| 49 | - } |
|
| 50 | - $job_parameters->set_extra_data( |
|
| 51 | - [ |
|
| 52 | - 'deletion_job_code' => $deletion_job_code, |
|
| 53 | - 'ids_to_delete' => $ids_to_delete |
|
| 54 | - ] |
|
| 55 | - ); |
|
| 56 | - // Find the job's actual size. |
|
| 57 | - $job_size = 0; |
|
| 58 | - foreach($ids_to_delete as $model_name => $ids){ |
|
| 59 | - $job_size += count($ids); |
|
| 60 | - } |
|
| 61 | - $job_parameters->set_job_size($job_size); |
|
| 62 | - return new JobStepResponse( |
|
| 63 | - $job_parameters, |
|
| 64 | - esc_html__('Beginning to delete items...', 'event_espresso') |
|
| 65 | - ); |
|
| 66 | - } |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + * @param JobParameters $job_parameters |
|
| 33 | + * @throws BatchRequestException |
|
| 34 | + * @return JobStepResponse |
|
| 35 | + */ |
|
| 36 | + public function create_job(JobParameters $job_parameters) |
|
| 37 | + { |
|
| 38 | + $deletion_job_code = $job_parameters->request_datum('deletion_job_code', array()); |
|
| 39 | + $roots = get_option('EEBatchDeletion' . $deletion_job_code, null); |
|
| 40 | + if($roots === null){ |
|
| 41 | + throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
| 42 | + } |
|
| 43 | + $ids_to_delete = []; |
|
| 44 | + foreach ($roots as $root) { |
|
| 45 | + if(! $root instanceof ModelObjNode){ |
|
| 46 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
| 47 | + } |
|
| 48 | + $ids_to_delete = array_replace_recursive($ids_to_delete, $root->getIds()); |
|
| 49 | + } |
|
| 50 | + $job_parameters->set_extra_data( |
|
| 51 | + [ |
|
| 52 | + 'deletion_job_code' => $deletion_job_code, |
|
| 53 | + 'ids_to_delete' => $ids_to_delete |
|
| 54 | + ] |
|
| 55 | + ); |
|
| 56 | + // Find the job's actual size. |
|
| 57 | + $job_size = 0; |
|
| 58 | + foreach($ids_to_delete as $model_name => $ids){ |
|
| 59 | + $job_size += count($ids); |
|
| 60 | + } |
|
| 61 | + $job_parameters->set_job_size($job_size); |
|
| 62 | + return new JobStepResponse( |
|
| 63 | + $job_parameters, |
|
| 64 | + esc_html__('Beginning to delete items...', 'event_espresso') |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Performs another step of the job |
|
| 70 | - * @param JobParameters $job_parameters |
|
| 71 | - * @param int $batch_size |
|
| 72 | - * @return JobStepResponse |
|
| 73 | - * @throws BatchRequestException |
|
| 74 | - */ |
|
| 75 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 76 | - { |
|
| 77 | - $units_processed = 0; |
|
| 78 | - $ids_to_delete = $job_parameters->extra_datum('ids_to_delete', []); |
|
| 79 | - $ids_remaining = []; |
|
| 80 | - foreach($ids_to_delete as $model_name => $ids){ |
|
| 81 | - if($units_processed < $batch_size){ |
|
| 82 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 83 | - $ids_to_delete_this_query = array_slice($ids, 0, $batch_size, true); |
|
| 84 | - if ($model->has_primary_key_field()) { |
|
| 85 | - $where_conditions = [ |
|
| 86 | - $model->primary_key_name() => [ |
|
| 87 | - 'IN', |
|
| 88 | - $ids |
|
| 89 | - ] |
|
| 90 | - ]; |
|
| 91 | - } else { |
|
| 92 | - $where_conditions = [ |
|
| 93 | - 'OR' => [] |
|
| 94 | - ]; |
|
| 95 | - foreach ($ids as $index_primary_key_string) { |
|
| 96 | - $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
| 97 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - $deletion_count = $model->delete_permanently( |
|
| 101 | - [ |
|
| 102 | - $where_conditions |
|
| 103 | - ], |
|
| 104 | - false |
|
| 105 | - ); |
|
| 106 | - $units_processed += $deletion_count; |
|
| 107 | - $remaining_ids = array_diff_key($ids, $ids_to_delete_this_query); |
|
| 108 | - // If there's any more from this model, we'll do them next time. |
|
| 109 | - if(count($remaining_ids) > 0){ |
|
| 110 | - $ids_remaining[$model_name] = $remaining_ids; |
|
| 111 | - } |
|
| 112 | - } else { |
|
| 113 | - $ids_remaining[$model_name] = $ids_to_delete[$model_name]; |
|
| 114 | - } |
|
| 115 | - $job_parameters->mark_processed($units_processed); |
|
| 116 | - if(empty($ids_remaining)){ |
|
| 117 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 118 | - return new JobStepResponse( |
|
| 119 | - $job_parameters, |
|
| 120 | - esc_html__('Deletion complete.', 'event_espresso') |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - $job_parameters->add_extra_data('ids_to_delete', $ids_remaining); |
|
| 124 | - return new JobStepResponse( |
|
| 125 | - $job_parameters, |
|
| 126 | - sprintf( |
|
| 127 | - esc_html__('Deleted %d items.', 'event_espresso'), |
|
| 128 | - $units_processed |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - } |
|
| 68 | + /** |
|
| 69 | + * Performs another step of the job |
|
| 70 | + * @param JobParameters $job_parameters |
|
| 71 | + * @param int $batch_size |
|
| 72 | + * @return JobStepResponse |
|
| 73 | + * @throws BatchRequestException |
|
| 74 | + */ |
|
| 75 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 76 | + { |
|
| 77 | + $units_processed = 0; |
|
| 78 | + $ids_to_delete = $job_parameters->extra_datum('ids_to_delete', []); |
|
| 79 | + $ids_remaining = []; |
|
| 80 | + foreach($ids_to_delete as $model_name => $ids){ |
|
| 81 | + if($units_processed < $batch_size){ |
|
| 82 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 83 | + $ids_to_delete_this_query = array_slice($ids, 0, $batch_size, true); |
|
| 84 | + if ($model->has_primary_key_field()) { |
|
| 85 | + $where_conditions = [ |
|
| 86 | + $model->primary_key_name() => [ |
|
| 87 | + 'IN', |
|
| 88 | + $ids |
|
| 89 | + ] |
|
| 90 | + ]; |
|
| 91 | + } else { |
|
| 92 | + $where_conditions = [ |
|
| 93 | + 'OR' => [] |
|
| 94 | + ]; |
|
| 95 | + foreach ($ids as $index_primary_key_string) { |
|
| 96 | + $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
| 97 | + $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + $deletion_count = $model->delete_permanently( |
|
| 101 | + [ |
|
| 102 | + $where_conditions |
|
| 103 | + ], |
|
| 104 | + false |
|
| 105 | + ); |
|
| 106 | + $units_processed += $deletion_count; |
|
| 107 | + $remaining_ids = array_diff_key($ids, $ids_to_delete_this_query); |
|
| 108 | + // If there's any more from this model, we'll do them next time. |
|
| 109 | + if(count($remaining_ids) > 0){ |
|
| 110 | + $ids_remaining[$model_name] = $remaining_ids; |
|
| 111 | + } |
|
| 112 | + } else { |
|
| 113 | + $ids_remaining[$model_name] = $ids_to_delete[$model_name]; |
|
| 114 | + } |
|
| 115 | + $job_parameters->mark_processed($units_processed); |
|
| 116 | + if(empty($ids_remaining)){ |
|
| 117 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 118 | + return new JobStepResponse( |
|
| 119 | + $job_parameters, |
|
| 120 | + esc_html__('Deletion complete.', 'event_espresso') |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + $job_parameters->add_extra_data('ids_to_delete', $ids_remaining); |
|
| 124 | + return new JobStepResponse( |
|
| 125 | + $job_parameters, |
|
| 126 | + sprintf( |
|
| 127 | + esc_html__('Deleted %d items.', 'event_espresso'), |
|
| 128 | + $units_processed |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Performs any clean-up logic when we know the job is completed |
|
| 136 | - * @param JobParameters $job_parameters |
|
| 137 | - * @return JobStepResponse |
|
| 138 | - * @throws BatchRequestException |
|
| 139 | - */ |
|
| 140 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 141 | - { |
|
| 142 | - delete_option( |
|
| 143 | - 'EEBatchDeletion' . $job_parameters->extra_datum('deletion_job_code') |
|
| 144 | - ); |
|
| 145 | - } |
|
| 134 | + /** |
|
| 135 | + * Performs any clean-up logic when we know the job is completed |
|
| 136 | + * @param JobParameters $job_parameters |
|
| 137 | + * @return JobStepResponse |
|
| 138 | + * @throws BatchRequestException |
|
| 139 | + */ |
|
| 140 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 141 | + { |
|
| 142 | + delete_option( |
|
| 143 | + 'EEBatchDeletion' . $job_parameters->extra_datum('deletion_job_code') |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | 146 | } |
| 147 | 147 | // End of file EventDeletion.php |
| 148 | 148 | // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | public function create_job(JobParameters $job_parameters) |
| 37 | 37 | { |
| 38 | 38 | $deletion_job_code = $job_parameters->request_datum('deletion_job_code', array()); |
| 39 | - $roots = get_option('EEBatchDeletion' . $deletion_job_code, null); |
|
| 40 | - if($roots === null){ |
|
| 39 | + $roots = get_option('EEBatchDeletion'.$deletion_job_code, null); |
|
| 40 | + if ($roots === null) { |
|
| 41 | 41 | throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
| 42 | 42 | } |
| 43 | 43 | $ids_to_delete = []; |
| 44 | 44 | foreach ($roots as $root) { |
| 45 | - if(! $root instanceof ModelObjNode){ |
|
| 45 | + if ( ! $root instanceof ModelObjNode) { |
|
| 46 | 46 | throw new UnexpectedEntityException($root, 'ModelObjNode'); |
| 47 | 47 | } |
| 48 | 48 | $ids_to_delete = array_replace_recursive($ids_to_delete, $root->getIds()); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | // Find the job's actual size. |
| 57 | 57 | $job_size = 0; |
| 58 | - foreach($ids_to_delete as $model_name => $ids){ |
|
| 58 | + foreach ($ids_to_delete as $model_name => $ids) { |
|
| 59 | 59 | $job_size += count($ids); |
| 60 | 60 | } |
| 61 | 61 | $job_parameters->set_job_size($job_size); |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | $units_processed = 0; |
| 78 | 78 | $ids_to_delete = $job_parameters->extra_datum('ids_to_delete', []); |
| 79 | 79 | $ids_remaining = []; |
| 80 | - foreach($ids_to_delete as $model_name => $ids){ |
|
| 81 | - if($units_processed < $batch_size){ |
|
| 80 | + foreach ($ids_to_delete as $model_name => $ids) { |
|
| 81 | + if ($units_processed < $batch_size) { |
|
| 82 | 82 | $model = EE_Registry::instance()->load_model($model_name); |
| 83 | 83 | $ids_to_delete_this_query = array_slice($ids, 0, $batch_size, true); |
| 84 | 84 | if ($model->has_primary_key_field()) { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | ]; |
| 95 | 95 | foreach ($ids as $index_primary_key_string) { |
| 96 | 96 | $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
| 97 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
| 97 | + $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | $deletion_count = $model->delete_permanently( |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | $units_processed += $deletion_count; |
| 107 | 107 | $remaining_ids = array_diff_key($ids, $ids_to_delete_this_query); |
| 108 | 108 | // If there's any more from this model, we'll do them next time. |
| 109 | - if(count($remaining_ids) > 0){ |
|
| 109 | + if (count($remaining_ids) > 0) { |
|
| 110 | 110 | $ids_remaining[$model_name] = $remaining_ids; |
| 111 | 111 | } |
| 112 | 112 | } else { |
| 113 | 113 | $ids_remaining[$model_name] = $ids_to_delete[$model_name]; |
| 114 | 114 | } |
| 115 | 115 | $job_parameters->mark_processed($units_processed); |
| 116 | - if(empty($ids_remaining)){ |
|
| 116 | + if (empty($ids_remaining)) { |
|
| 117 | 117 | $job_parameters->set_status(JobParameters::status_complete); |
| 118 | 118 | return new JobStepResponse( |
| 119 | 119 | $job_parameters, |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | public function cleanup_job(JobParameters $job_parameters) |
| 141 | 141 | { |
| 142 | 142 | delete_option( |
| 143 | - 'EEBatchDeletion' . $job_parameters->extra_datum('deletion_job_code') |
|
| 143 | + 'EEBatchDeletion'.$job_parameters->extra_datum('deletion_job_code') |
|
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -27,126 +27,126 @@ |
||
| 27 | 27 | { |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - * @param JobParameters $job_parameters |
|
| 33 | - * @throws BatchRequestException |
|
| 34 | - * @return JobStepResponse |
|
| 35 | - */ |
|
| 36 | - public function create_job(JobParameters $job_parameters) |
|
| 37 | - { |
|
| 38 | - // Set the "root" model objects we will want to delete (record their ID and model) |
|
| 39 | - $event_ids = $job_parameters->request_datum('EVT_ID', array()); |
|
| 40 | - // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets, |
|
| 41 | - // prices, message templates, etc, whose model definition doesn't make them dependent on events. But, |
|
| 42 | - // we have no UI to access them independent of events, so they may as well get deleted too.) |
|
| 43 | - $model_objects_to_delete = []; |
|
| 44 | - foreach ($event_ids as $event_id) { |
|
| 45 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + * @param JobParameters $job_parameters |
|
| 33 | + * @throws BatchRequestException |
|
| 34 | + * @return JobStepResponse |
|
| 35 | + */ |
|
| 36 | + public function create_job(JobParameters $job_parameters) |
|
| 37 | + { |
|
| 38 | + // Set the "root" model objects we will want to delete (record their ID and model) |
|
| 39 | + $event_ids = $job_parameters->request_datum('EVT_ID', array()); |
|
| 40 | + // Find all the root nodes to delete (this isn't just events, because there's other data, like related tickets, |
|
| 41 | + // prices, message templates, etc, whose model definition doesn't make them dependent on events. But, |
|
| 42 | + // we have no UI to access them independent of events, so they may as well get deleted too.) |
|
| 43 | + $model_objects_to_delete = []; |
|
| 44 | + foreach ($event_ids as $event_id) { |
|
| 45 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 46 | 46 | // $model_objects_to_delete[] = $event; |
| 47 | - // Also, we want to delete their related, non-global, tickets, prices and message templates |
|
| 48 | - $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
| 49 | - [ |
|
| 50 | - [ |
|
| 51 | - 'TKT_is_default' => false, |
|
| 52 | - 'Datetime.EVT_ID' => $event_id |
|
| 53 | - ] |
|
| 54 | - ] |
|
| 55 | - ); |
|
| 56 | - $related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted( |
|
| 57 | - [ |
|
| 58 | - [ |
|
| 59 | - 'PRC_is_default' => false, |
|
| 60 | - 'Ticket.Datetime.EVT_ID' => $event_id |
|
| 61 | - ] |
|
| 62 | - ] |
|
| 63 | - ); |
|
| 64 | - $related_message_templates = $event->get_many_related( |
|
| 65 | - 'Message_Template_Group', |
|
| 66 | - [ |
|
| 67 | - [ |
|
| 68 | - 'MTP_is_global' => false |
|
| 69 | - ] |
|
| 70 | - ] |
|
| 71 | - ); |
|
| 72 | - $model_objects_to_delete = array_merge( |
|
| 73 | - $model_objects_to_delete, |
|
| 74 | - [$event], |
|
| 75 | - $related_non_global_tickets, |
|
| 76 | - $related_non_global_prices, |
|
| 77 | - $related_message_templates |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - $roots = []; |
|
| 81 | - foreach($model_objects_to_delete as $model_object){ |
|
| 82 | - $roots[] = new ModelObjNode($model_objects_to_delete); |
|
| 83 | - } |
|
| 84 | - $job_parameters->add_extra_data('roots', $roots); |
|
| 85 | - // Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give |
|
| 86 | - // an accurate count.) |
|
| 87 | - $estimated_work_per_model_obj = 100; |
|
| 88 | - $job_parameters->set_job_size(count($roots) * $estimated_work_per_model_obj); |
|
| 89 | - return new JobStepResponse( |
|
| 90 | - $job_parameters, |
|
| 91 | - esc_html__('Identified main items for deletion...', 'event_espresso') |
|
| 92 | - ); |
|
| 93 | - } |
|
| 47 | + // Also, we want to delete their related, non-global, tickets, prices and message templates |
|
| 48 | + $related_non_global_tickets = EEM_Ticket::instance()->get_all_deleted_and_undeleted( |
|
| 49 | + [ |
|
| 50 | + [ |
|
| 51 | + 'TKT_is_default' => false, |
|
| 52 | + 'Datetime.EVT_ID' => $event_id |
|
| 53 | + ] |
|
| 54 | + ] |
|
| 55 | + ); |
|
| 56 | + $related_non_global_prices = EEM_Price::instance()->get_all_deleted_and_undeleted( |
|
| 57 | + [ |
|
| 58 | + [ |
|
| 59 | + 'PRC_is_default' => false, |
|
| 60 | + 'Ticket.Datetime.EVT_ID' => $event_id |
|
| 61 | + ] |
|
| 62 | + ] |
|
| 63 | + ); |
|
| 64 | + $related_message_templates = $event->get_many_related( |
|
| 65 | + 'Message_Template_Group', |
|
| 66 | + [ |
|
| 67 | + [ |
|
| 68 | + 'MTP_is_global' => false |
|
| 69 | + ] |
|
| 70 | + ] |
|
| 71 | + ); |
|
| 72 | + $model_objects_to_delete = array_merge( |
|
| 73 | + $model_objects_to_delete, |
|
| 74 | + [$event], |
|
| 75 | + $related_non_global_tickets, |
|
| 76 | + $related_non_global_prices, |
|
| 77 | + $related_message_templates |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + $roots = []; |
|
| 81 | + foreach($model_objects_to_delete as $model_object){ |
|
| 82 | + $roots[] = new ModelObjNode($model_objects_to_delete); |
|
| 83 | + } |
|
| 84 | + $job_parameters->add_extra_data('roots', $roots); |
|
| 85 | + // Set an estimate of how long this will take (we're discovering as we go, so it seems impossible to give |
|
| 86 | + // an accurate count.) |
|
| 87 | + $estimated_work_per_model_obj = 100; |
|
| 88 | + $job_parameters->set_job_size(count($roots) * $estimated_work_per_model_obj); |
|
| 89 | + return new JobStepResponse( |
|
| 90 | + $job_parameters, |
|
| 91 | + esc_html__('Identified main items for deletion...', 'event_espresso') |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Performs another step of the job |
|
| 97 | - * @param JobParameters $job_parameters |
|
| 98 | - * @param int $batch_size |
|
| 99 | - * @return JobStepResponse |
|
| 100 | - * @throws BatchRequestException |
|
| 101 | - */ |
|
| 102 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 103 | - { |
|
| 104 | - $units_processed = 0; |
|
| 105 | - foreach($job_parameters->extra_datum('roots', array()) as $root_node){ |
|
| 106 | - if($units_processed >= $batch_size){ |
|
| 107 | - break; |
|
| 108 | - } |
|
| 109 | - if(! $root_node instanceof ModelObjNode){ |
|
| 110 | - throw new InvalidClassException('ModelObjNode'); |
|
| 111 | - } |
|
| 112 | - if($root_node->isComplete()){ |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - $units_processed += $root_node->visit($batch_size); |
|
| 116 | - } |
|
| 117 | - $job_parameters->mark_processed($units_processed); |
|
| 118 | - // If the most-recently processed root node is complete, we must be all done! |
|
| 119 | - if($root_node->isComplete()){ |
|
| 120 | - $deletion_job_code = wp_generate_password(8, false); |
|
| 121 | - add_option('EEBatchDeletion' . $deletion_job_code, $job_parameters->extra_datum('roots')); |
|
| 122 | - return new JobStepResponse( |
|
| 123 | - $job_parameters, |
|
| 124 | - esc_html__('Finished identifying items for deletion.', 'event_espresso'), |
|
| 125 | - [ |
|
| 126 | - 'deletion_job_code' => $deletion_job_code |
|
| 127 | - ] |
|
| 128 | - ); |
|
| 129 | - } else { |
|
| 130 | - return new JobStepResponse( |
|
| 131 | - $job_parameters, |
|
| 132 | - sprintf( |
|
| 133 | - esc_html__('Identified %d items for deletions.', 'event_espresso'), |
|
| 134 | - $units_processed |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - } |
|
| 95 | + /** |
|
| 96 | + * Performs another step of the job |
|
| 97 | + * @param JobParameters $job_parameters |
|
| 98 | + * @param int $batch_size |
|
| 99 | + * @return JobStepResponse |
|
| 100 | + * @throws BatchRequestException |
|
| 101 | + */ |
|
| 102 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 103 | + { |
|
| 104 | + $units_processed = 0; |
|
| 105 | + foreach($job_parameters->extra_datum('roots', array()) as $root_node){ |
|
| 106 | + if($units_processed >= $batch_size){ |
|
| 107 | + break; |
|
| 108 | + } |
|
| 109 | + if(! $root_node instanceof ModelObjNode){ |
|
| 110 | + throw new InvalidClassException('ModelObjNode'); |
|
| 111 | + } |
|
| 112 | + if($root_node->isComplete()){ |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + $units_processed += $root_node->visit($batch_size); |
|
| 116 | + } |
|
| 117 | + $job_parameters->mark_processed($units_processed); |
|
| 118 | + // If the most-recently processed root node is complete, we must be all done! |
|
| 119 | + if($root_node->isComplete()){ |
|
| 120 | + $deletion_job_code = wp_generate_password(8, false); |
|
| 121 | + add_option('EEBatchDeletion' . $deletion_job_code, $job_parameters->extra_datum('roots')); |
|
| 122 | + return new JobStepResponse( |
|
| 123 | + $job_parameters, |
|
| 124 | + esc_html__('Finished identifying items for deletion.', 'event_espresso'), |
|
| 125 | + [ |
|
| 126 | + 'deletion_job_code' => $deletion_job_code |
|
| 127 | + ] |
|
| 128 | + ); |
|
| 129 | + } else { |
|
| 130 | + return new JobStepResponse( |
|
| 131 | + $job_parameters, |
|
| 132 | + sprintf( |
|
| 133 | + esc_html__('Identified %d items for deletions.', 'event_espresso'), |
|
| 134 | + $units_processed |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Performs any clean-up logic when we know the job is completed |
|
| 142 | - * @param JobParameters $job_parameters |
|
| 143 | - * @return JobStepResponse |
|
| 144 | - * @throws BatchRequestException |
|
| 145 | - */ |
|
| 146 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 147 | - { |
|
| 148 | - // Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion |
|
| 149 | - } |
|
| 140 | + /** |
|
| 141 | + * Performs any clean-up logic when we know the job is completed |
|
| 142 | + * @param JobParameters $job_parameters |
|
| 143 | + * @return JobStepResponse |
|
| 144 | + * @throws BatchRequestException |
|
| 145 | + */ |
|
| 146 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 147 | + { |
|
| 148 | + // Nothing much to do. We can't delete the option with the built tree because we may need it in a moment for the deletion |
|
| 149 | + } |
|
| 150 | 150 | } |
| 151 | 151 | // End of file EventDeletion.php |
| 152 | 152 | // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | ); |
| 79 | 79 | } |
| 80 | 80 | $roots = []; |
| 81 | - foreach($model_objects_to_delete as $model_object){ |
|
| 81 | + foreach ($model_objects_to_delete as $model_object) { |
|
| 82 | 82 | $roots[] = new ModelObjNode($model_objects_to_delete); |
| 83 | 83 | } |
| 84 | 84 | $job_parameters->add_extra_data('roots', $roots); |
@@ -102,23 +102,23 @@ discard block |
||
| 102 | 102 | public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
| 103 | 103 | { |
| 104 | 104 | $units_processed = 0; |
| 105 | - foreach($job_parameters->extra_datum('roots', array()) as $root_node){ |
|
| 106 | - if($units_processed >= $batch_size){ |
|
| 105 | + foreach ($job_parameters->extra_datum('roots', array()) as $root_node) { |
|
| 106 | + if ($units_processed >= $batch_size) { |
|
| 107 | 107 | break; |
| 108 | 108 | } |
| 109 | - if(! $root_node instanceof ModelObjNode){ |
|
| 109 | + if ( ! $root_node instanceof ModelObjNode) { |
|
| 110 | 110 | throw new InvalidClassException('ModelObjNode'); |
| 111 | 111 | } |
| 112 | - if($root_node->isComplete()){ |
|
| 112 | + if ($root_node->isComplete()) { |
|
| 113 | 113 | continue; |
| 114 | 114 | } |
| 115 | 115 | $units_processed += $root_node->visit($batch_size); |
| 116 | 116 | } |
| 117 | 117 | $job_parameters->mark_processed($units_processed); |
| 118 | 118 | // If the most-recently processed root node is complete, we must be all done! |
| 119 | - if($root_node->isComplete()){ |
|
| 119 | + if ($root_node->isComplete()) { |
|
| 120 | 120 | $deletion_job_code = wp_generate_password(8, false); |
| 121 | - add_option('EEBatchDeletion' . $deletion_job_code, $job_parameters->extra_datum('roots')); |
|
| 121 | + add_option('EEBatchDeletion'.$deletion_job_code, $job_parameters->extra_datum('roots')); |
|
| 122 | 122 | return new JobStepResponse( |
| 123 | 123 | $job_parameters, |
| 124 | 124 | esc_html__('Finished identifying items for deletion.', 'event_espresso'), |