PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / woocommerce / action-scheduler / classes / migration / ActionScheduler_DBStoreMigrator.php

ActionScheduler_DBStoreMigrator.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at vendor/woocommerce/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php

53 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_DBStoreMigrator
5 *
6 * A class for direct saving of actions to the table data store during migration.
7 *
8 * @since 3.0.0
9 */
10 class ActionScheduler_DBStoreMigrator extends ActionScheduler_DBStore {
11
12 /**
13 * Save an action with optional last attempt date.
14 *
15 * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved,
16 * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save
17 * that when first saving the action.
18 *
19 * @param ActionScheduler_Action $action Action to migrate.
20 * @param null|DateTime $scheduled_date Optional date of the first instance to store.
21 * @param null|DateTime $last_attempt_date Optional date the action was last attempted.
22 *
23 * @return string The action ID
24 * @throws \RuntimeException When the action is not saved.
25 */
26 public function save_action( ActionScheduler_Action $action, ?DateTime $scheduled_date = null, ?DateTime $last_attempt_date = null ) {
27 try {
28 /**
29 * Global.
30 *
31 * @var \wpdb $wpdb
32 */
33 global $wpdb;
34
35 $action_id = parent::save_action( $action, $scheduled_date );
36
37 if ( null !== $last_attempt_date ) {
38 $data = array(
39 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ),
40 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ),
41 );
42
43 $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
44 }
45
46 return $action_id;
47 } catch ( \Exception $e ) {
48 // translators: %s is an error message.
49 throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
50 }
51 }
52 }
53