PluginProbe
WANotifier for Forms and Actions / 2.7.13
WANotifier for Forms and Actions v2.7.13
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / migration / ActionScheduler_DBStoreMigrator.php

ActionScheduler_DBStoreMigrator.php in WANotifier for Forms and Actions 2.7.13, at libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php

48 lines 1.7 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
20 * @param \DateTime $scheduled_date Optional date of the first instance to store.
21 * @param \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 /** @var \wpdb $wpdb */
29 global $wpdb;
30
31 $action_id = parent::save_action( $action, $scheduled_date );
32
33 if ( null !== $last_attempt_date ) {
34 $data = [
35 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ),
36 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ),
37 ];
38
39 $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
40 }
41
42 return $action_id;
43 } catch ( \Exception $e ) {
44 throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
45 }
46 }
47 }
48