PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 114
Lasso Lite – Affiliate Link Manager & Product Displays v114
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
simple-urls / classes / processes / class-revert-all.php

class-revert-all.php in Lasso Lite – Affiliate Link Manager & Product Displays 114, at classes/processes/class-revert-all.php

115 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Declare class Revert_All
4 *
5 * @package Revert_All
6 */
7
8 namespace LassoLite\Classes\Processes;
9
10 use LassoLite\Classes\Import as Lasso_Import;
11 use LassoLite\Classes\Lasso_DB;
12 use LassoLite\Classes\Processes\Process;
13 use LassoLite\Classes\Processes\Import_All;
14
15 use LassoLite\Models\Model;
16
17 /**
18 * Revert_All
19 */
20 class Revert_All extends Process {
21 const LIMIT = 500;
22 const OPTION = 'lasso_lite_revert_all_enable';
23
24 /**
25 * Action name
26 *
27 * @var string $action
28 */
29 protected $action = 'lassolite_revert_process_all';
30
31 /**
32 * Log name
33 *
34 * @var string $log_name
35 */
36 protected $log_name = 'lite_bulk_revert';
37
38 /**
39 * Task
40 *
41 * Override this method to perform any actions required on each
42 * queue item. Return the modified item for further processing
43 * in the next pass through. Or, return false to remove the
44 * item from the queue.
45 *
46 * @param mixed $data Queue item to iterate over.
47 *
48 * @return mixed
49 */
50 public function task( $data ) {
51 $start_time = microtime( true );
52
53 $lasso_import = new Lasso_Import();
54 $lasso_import->process_single_link_revert( $data['revert_id'], $data['source'] );
55
56 $this->set_processing_runtime();
57 $time_end = microtime( true );
58 $execution_time = round( $time_end - $start_time, 2 );
59
60 return false;
61 }
62
63 /**
64 * Prepare data for process
65 *
66 * @param string $filter_plugin Plugin name. Default to null (all plugins).
67 */
68 public function revert( $filter_plugin = null ) {
69 // ? check whether process is age out and make it can work on Lasso UI via ajax requests
70 $this->is_process_age_out();
71
72 if ( $this->is_process_running() ) {
73 return false;
74 }
75
76 $lasso_db = new Lasso_DB();
77
78 $sql = $lasso_db->get_revertable_urls_query( $filter_plugin );
79 $sql = $lasso_db->paginate( $sql, 1, self::LIMIT );
80 $all_reverts = Model::get_results( $sql );
81 $count = count( $all_reverts );
82
83 if ( $count <= 0 ) {
84 update_option( self::OPTION, '0' );
85 return false;
86 }
87 update_option( self::OPTION, '1' );
88
89 // ? disable/remove import all process
90 $import_all_process = new Import_All();
91 $import_all_process->remove_process();
92 update_option( Import_All::OPTION, '0' );
93
94 foreach ( $all_reverts as $revert ) {
95 if ( empty( $revert->import_id ) || empty( $revert->import_source ) ) {
96 continue;
97 }
98 $this->push_to_queue(
99 array(
100 'revert_id' => $revert->import_id,
101 'source' => $revert->import_source,
102 )
103 );
104 }
105
106 $this->set_total( $count );
107 $this->set_log_file_name( $this->log_name );
108 $this->task_start_log();
109 // ? save queue
110 $this->save()->dispatch();
111
112 return true;
113 }
114 }
115