@@ -28,356 +28,356 @@ |
||
| 28 | 28 | class EED_Batch extends EED_Module |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 33 | - * processes data only |
|
| 34 | - */ |
|
| 35 | - const batch_job = 'job'; |
|
| 36 | - /** |
|
| 37 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 38 | - * produces a file for download |
|
| 39 | - */ |
|
| 40 | - const batch_file_job = 'file'; |
|
| 41 | - /** |
|
| 42 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 43 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 44 | - * at all |
|
| 45 | - */ |
|
| 46 | - const batch_not_job = 'none'; |
|
| 31 | + /** |
|
| 32 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 33 | + * processes data only |
|
| 34 | + */ |
|
| 35 | + const batch_job = 'job'; |
|
| 36 | + /** |
|
| 37 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
| 38 | + * produces a file for download |
|
| 39 | + */ |
|
| 40 | + const batch_file_job = 'file'; |
|
| 41 | + /** |
|
| 42 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
| 43 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
| 44 | + * at all |
|
| 45 | + */ |
|
| 46 | + const batch_not_job = 'none'; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * |
|
| 50 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 51 | - */ |
|
| 52 | - protected $_batch_request_type = null; |
|
| 48 | + /** |
|
| 49 | + * |
|
| 50 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
| 51 | + */ |
|
| 52 | + protected $_batch_request_type = null; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Because we want to use the response in both the localized JS and in the body |
|
| 56 | - * we need to make this response available between method calls |
|
| 57 | - * |
|
| 58 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 59 | - */ |
|
| 60 | - protected $_job_step_response = null; |
|
| 54 | + /** |
|
| 55 | + * Because we want to use the response in both the localized JS and in the body |
|
| 56 | + * we need to make this response available between method calls |
|
| 57 | + * |
|
| 58 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 59 | + */ |
|
| 60 | + protected $_job_step_response = null; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var LoaderInterface |
|
| 64 | - */ |
|
| 65 | - protected $loader; |
|
| 62 | + /** |
|
| 63 | + * @var LoaderInterface |
|
| 64 | + */ |
|
| 65 | + protected $loader; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Gets the batch instance |
|
| 69 | - * |
|
| 70 | - * @return EED_Batch |
|
| 71 | - */ |
|
| 72 | - public static function instance() |
|
| 73 | - { |
|
| 74 | - return self::get_instance(); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Gets the batch instance |
|
| 69 | + * |
|
| 70 | + * @return EED_Batch |
|
| 71 | + */ |
|
| 72 | + public static function instance() |
|
| 73 | + { |
|
| 74 | + return self::get_instance(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 79 | - * because it's an attack vector and there are currently no implementations |
|
| 80 | - */ |
|
| 81 | - public static function set_hooks() |
|
| 82 | - { |
|
| 83 | - // because this is a possibel attack vector, let's have this disabled until |
|
| 84 | - // we at least have a real use for it on the frontend |
|
| 85 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 86 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 87 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 88 | - } |
|
| 89 | - } |
|
| 77 | + /** |
|
| 78 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
| 79 | + * because it's an attack vector and there are currently no implementations |
|
| 80 | + */ |
|
| 81 | + public static function set_hooks() |
|
| 82 | + { |
|
| 83 | + // because this is a possibel attack vector, let's have this disabled until |
|
| 84 | + // we at least have a real use for it on the frontend |
|
| 85 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
| 86 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 87 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Initializes some hooks for the admin in order to run batch jobs |
|
| 93 | - */ |
|
| 94 | - public static function set_hooks_admin() |
|
| 95 | - { |
|
| 96 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 97 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 91 | + /** |
|
| 92 | + * Initializes some hooks for the admin in order to run batch jobs |
|
| 93 | + */ |
|
| 94 | + public static function set_hooks_admin() |
|
| 95 | + { |
|
| 96 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
| 97 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
| 98 | 98 | |
| 99 | - // ajax |
|
| 100 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 101 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 102 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 103 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 104 | - } |
|
| 99 | + // ajax |
|
| 100 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 101 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 102 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
| 103 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @since $VID:$ |
|
| 108 | - * @return LoaderInterface |
|
| 109 | - * @throws InvalidArgumentException |
|
| 110 | - * @throws InvalidDataTypeException |
|
| 111 | - * @throws InvalidInterfaceException |
|
| 112 | - */ |
|
| 113 | - protected function getLoader() |
|
| 114 | - { |
|
| 115 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 116 | - $this->loader = LoaderFactory::getLoader(); |
|
| 117 | - } |
|
| 118 | - return $this->loader; |
|
| 119 | - } |
|
| 106 | + /** |
|
| 107 | + * @since $VID:$ |
|
| 108 | + * @return LoaderInterface |
|
| 109 | + * @throws InvalidArgumentException |
|
| 110 | + * @throws InvalidDataTypeException |
|
| 111 | + * @throws InvalidInterfaceException |
|
| 112 | + */ |
|
| 113 | + protected function getLoader() |
|
| 114 | + { |
|
| 115 | + if (!$this->loader instanceof LoaderInterface) { |
|
| 116 | + $this->loader = LoaderFactory::getLoader(); |
|
| 117 | + } |
|
| 118 | + return $this->loader; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 123 | - */ |
|
| 124 | - public function enqueue_scripts() |
|
| 125 | - { |
|
| 126 | - if (isset($_REQUEST['espresso_batch']) |
|
| 127 | - || |
|
| 128 | - ( |
|
| 129 | - isset($_REQUEST['page']) |
|
| 130 | - && $_REQUEST['page'] == 'espresso_batch' |
|
| 131 | - ) |
|
| 132 | - ) { |
|
| 133 | - switch ($this->batch_request_type()) { |
|
| 134 | - case self::batch_job: |
|
| 135 | - $this->enqueue_scripts_styles_batch_create(); |
|
| 136 | - break; |
|
| 137 | - case self::batch_file_job: |
|
| 138 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 121 | + /** |
|
| 122 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
| 123 | + */ |
|
| 124 | + public function enqueue_scripts() |
|
| 125 | + { |
|
| 126 | + if (isset($_REQUEST['espresso_batch']) |
|
| 127 | + || |
|
| 128 | + ( |
|
| 129 | + isset($_REQUEST['page']) |
|
| 130 | + && $_REQUEST['page'] == 'espresso_batch' |
|
| 131 | + ) |
|
| 132 | + ) { |
|
| 133 | + switch ($this->batch_request_type()) { |
|
| 134 | + case self::batch_job: |
|
| 135 | + $this->enqueue_scripts_styles_batch_create(); |
|
| 136 | + break; |
|
| 137 | + case self::batch_file_job: |
|
| 138 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 146 | - */ |
|
| 147 | - public function enqueue_scripts_styles_batch_create() |
|
| 148 | - { |
|
| 149 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 150 | - wp_enqueue_script( |
|
| 151 | - 'batch_runner_init', |
|
| 152 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 153 | - array('batch_runner'), |
|
| 154 | - EVENT_ESPRESSO_VERSION, |
|
| 155 | - true |
|
| 156 | - ); |
|
| 157 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 158 | - wp_localize_script( |
|
| 159 | - 'batch_runner_init', |
|
| 160 | - 'ee_job_i18n', |
|
| 161 | - array( |
|
| 162 | - 'return_url' => $_REQUEST['return_url'], |
|
| 163 | - ) |
|
| 164 | - ); |
|
| 165 | - } |
|
| 144 | + /** |
|
| 145 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
| 146 | + */ |
|
| 147 | + public function enqueue_scripts_styles_batch_create() |
|
| 148 | + { |
|
| 149 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 150 | + wp_enqueue_script( |
|
| 151 | + 'batch_runner_init', |
|
| 152 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
| 153 | + array('batch_runner'), |
|
| 154 | + EVENT_ESPRESSO_VERSION, |
|
| 155 | + true |
|
| 156 | + ); |
|
| 157 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 158 | + wp_localize_script( |
|
| 159 | + 'batch_runner_init', |
|
| 160 | + 'ee_job_i18n', |
|
| 161 | + array( |
|
| 162 | + 'return_url' => $_REQUEST['return_url'], |
|
| 163 | + ) |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 169 | - */ |
|
| 170 | - public function enqueue_scripts_styles_batch_file_create() |
|
| 171 | - { |
|
| 172 | - // creates a job based on the request variable |
|
| 173 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 174 | - wp_enqueue_script( |
|
| 175 | - 'batch_file_runner_init', |
|
| 176 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 177 | - array('batch_runner'), |
|
| 178 | - EVENT_ESPRESSO_VERSION, |
|
| 179 | - true |
|
| 180 | - ); |
|
| 181 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 182 | - wp_localize_script( |
|
| 183 | - 'batch_file_runner_init', |
|
| 184 | - 'ee_job_i18n', |
|
| 185 | - array( |
|
| 186 | - 'download_and_redirecting' => sprintf( |
|
| 187 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 188 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 189 | - '</a>' |
|
| 190 | - ), |
|
| 191 | - 'return_url' => $_REQUEST['return_url'], |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 167 | + /** |
|
| 168 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
| 169 | + */ |
|
| 170 | + public function enqueue_scripts_styles_batch_file_create() |
|
| 171 | + { |
|
| 172 | + // creates a job based on the request variable |
|
| 173 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
| 174 | + wp_enqueue_script( |
|
| 175 | + 'batch_file_runner_init', |
|
| 176 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 177 | + array('batch_runner'), |
|
| 178 | + EVENT_ESPRESSO_VERSION, |
|
| 179 | + true |
|
| 180 | + ); |
|
| 181 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
| 182 | + wp_localize_script( |
|
| 183 | + 'batch_file_runner_init', |
|
| 184 | + 'ee_job_i18n', |
|
| 185 | + array( |
|
| 186 | + 'download_and_redirecting' => sprintf( |
|
| 187 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
| 188 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 189 | + '</a>' |
|
| 190 | + ), |
|
| 191 | + 'return_url' => $_REQUEST['return_url'], |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Enqueues scripts and styles common to any batch job, and creates |
|
| 198 | - * a job from the request data, and stores the response in the |
|
| 199 | - * $this->_job_step_response property |
|
| 200 | - * |
|
| 201 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 202 | - */ |
|
| 203 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 204 | - { |
|
| 205 | - wp_register_script( |
|
| 206 | - 'progress_bar', |
|
| 207 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 208 | - array('jquery') |
|
| 209 | - ); |
|
| 210 | - wp_enqueue_style( |
|
| 211 | - 'progress_bar', |
|
| 212 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 213 | - array(), |
|
| 214 | - EVENT_ESPRESSO_VERSION |
|
| 215 | - ); |
|
| 216 | - wp_enqueue_script( |
|
| 217 | - 'batch_runner', |
|
| 218 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 219 | - array('progress_bar') |
|
| 220 | - ); |
|
| 221 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 222 | - wp_localize_script( |
|
| 223 | - 'batch_runner', |
|
| 224 | - 'eei18n', |
|
| 225 | - array( |
|
| 226 | - 'ajax_url' => WP_AJAX_URL, |
|
| 227 | - 'is_admin' => (bool) is_admin(), |
|
| 228 | - 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 232 | - $request_data = array_diff_key( |
|
| 233 | - $_REQUEST, |
|
| 234 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 235 | - ); |
|
| 236 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 237 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 238 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 239 | - // remember the response for later. We need it to display the page body |
|
| 240 | - $this->_job_step_response = $job_response; |
|
| 241 | - return $job_response; |
|
| 242 | - } |
|
| 196 | + /** |
|
| 197 | + * Enqueues scripts and styles common to any batch job, and creates |
|
| 198 | + * a job from the request data, and stores the response in the |
|
| 199 | + * $this->_job_step_response property |
|
| 200 | + * |
|
| 201 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 202 | + */ |
|
| 203 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
| 204 | + { |
|
| 205 | + wp_register_script( |
|
| 206 | + 'progress_bar', |
|
| 207 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 208 | + array('jquery') |
|
| 209 | + ); |
|
| 210 | + wp_enqueue_style( |
|
| 211 | + 'progress_bar', |
|
| 212 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 213 | + array(), |
|
| 214 | + EVENT_ESPRESSO_VERSION |
|
| 215 | + ); |
|
| 216 | + wp_enqueue_script( |
|
| 217 | + 'batch_runner', |
|
| 218 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 219 | + array('progress_bar') |
|
| 220 | + ); |
|
| 221 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
| 222 | + wp_localize_script( |
|
| 223 | + 'batch_runner', |
|
| 224 | + 'eei18n', |
|
| 225 | + array( |
|
| 226 | + 'ajax_url' => WP_AJAX_URL, |
|
| 227 | + 'is_admin' => (bool) is_admin(), |
|
| 228 | + 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
| 232 | + $request_data = array_diff_key( |
|
| 233 | + $_REQUEST, |
|
| 234 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
| 235 | + ); |
|
| 236 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 237 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
| 238 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 239 | + // remember the response for later. We need it to display the page body |
|
| 240 | + $this->_job_step_response = $job_response; |
|
| 241 | + return $job_response; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 246 | - * |
|
| 247 | - * @param string $template |
|
| 248 | - * @return string |
|
| 249 | - */ |
|
| 250 | - public function override_template($template) |
|
| 251 | - { |
|
| 252 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 253 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 254 | - } |
|
| 255 | - return $template; |
|
| 256 | - } |
|
| 244 | + /** |
|
| 245 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
| 246 | + * |
|
| 247 | + * @param string $template |
|
| 248 | + * @return string |
|
| 249 | + */ |
|
| 250 | + public function override_template($template) |
|
| 251 | + { |
|
| 252 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
| 253 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 254 | + } |
|
| 255 | + return $template; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Adds an admin page which doesn't appear in the admin menu |
|
| 260 | - */ |
|
| 261 | - public function register_admin_pages() |
|
| 262 | - { |
|
| 263 | - add_submenu_page( |
|
| 264 | - '', // parent slug. we don't want this to actually appear in the menu |
|
| 265 | - __('Batch Job', 'event_espresso'), // page title |
|
| 266 | - 'n/a', // menu title |
|
| 267 | - 'read', // we want this page to actually be accessible to anyone, |
|
| 268 | - 'espresso_batch', // menu slug |
|
| 269 | - array(self::instance(), 'show_admin_page') |
|
| 270 | - ); |
|
| 271 | - } |
|
| 258 | + /** |
|
| 259 | + * Adds an admin page which doesn't appear in the admin menu |
|
| 260 | + */ |
|
| 261 | + public function register_admin_pages() |
|
| 262 | + { |
|
| 263 | + add_submenu_page( |
|
| 264 | + '', // parent slug. we don't want this to actually appear in the menu |
|
| 265 | + __('Batch Job', 'event_espresso'), // page title |
|
| 266 | + 'n/a', // menu title |
|
| 267 | + 'read', // we want this page to actually be accessible to anyone, |
|
| 268 | + 'espresso_batch', // menu slug |
|
| 269 | + array(self::instance(), 'show_admin_page') |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 275 | - * of creating the job and localizing some data |
|
| 276 | - */ |
|
| 277 | - public function show_admin_page() |
|
| 278 | - { |
|
| 279 | - echo EEH_Template::locate_template( |
|
| 280 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 281 | - array('batch_request_type' => $this->batch_request_type()) |
|
| 282 | - ); |
|
| 283 | - } |
|
| 273 | + /** |
|
| 274 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
| 275 | + * of creating the job and localizing some data |
|
| 276 | + */ |
|
| 277 | + public function show_admin_page() |
|
| 278 | + { |
|
| 279 | + echo EEH_Template::locate_template( |
|
| 280 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 281 | + array('batch_request_type' => $this->batch_request_type()) |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Receives ajax calls for continuing a job |
|
| 287 | - */ |
|
| 288 | - public function batch_continue() |
|
| 289 | - { |
|
| 290 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 291 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 292 | - $response_obj = $batch_runner->continue_job($job_id); |
|
| 293 | - $this->_return_json($response_obj->to_array()); |
|
| 294 | - } |
|
| 285 | + /** |
|
| 286 | + * Receives ajax calls for continuing a job |
|
| 287 | + */ |
|
| 288 | + public function batch_continue() |
|
| 289 | + { |
|
| 290 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 291 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 292 | + $response_obj = $batch_runner->continue_job($job_id); |
|
| 293 | + $this->_return_json($response_obj->to_array()); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Receives the ajax call to cleanup a job |
|
| 298 | - * |
|
| 299 | - * @return type |
|
| 300 | - */ |
|
| 301 | - public function batch_cleanup() |
|
| 302 | - { |
|
| 303 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 304 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 305 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 306 | - $this->_return_json($response_obj->to_array()); |
|
| 307 | - } |
|
| 296 | + /** |
|
| 297 | + * Receives the ajax call to cleanup a job |
|
| 298 | + * |
|
| 299 | + * @return type |
|
| 300 | + */ |
|
| 301 | + public function batch_cleanup() |
|
| 302 | + { |
|
| 303 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
| 304 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
| 305 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 306 | + $this->_return_json($response_obj->to_array()); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Returns a json response |
|
| 312 | - * |
|
| 313 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 314 | - * |
|
| 315 | - * The returned json object is created from an array in the following format: |
|
| 316 | - * array( |
|
| 317 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 318 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 319 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 320 | - * args that might be included in here) |
|
| 321 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
| 322 | - * ) |
|
| 323 | - */ |
|
| 324 | - protected function _return_json($data) |
|
| 325 | - { |
|
| 326 | - $json = array( |
|
| 327 | - 'notices' => EE_Error::get_notices(), |
|
| 328 | - 'data' => $data, |
|
| 329 | - 'isEEajax' => true |
|
| 330 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 331 | - ); |
|
| 310 | + /** |
|
| 311 | + * Returns a json response |
|
| 312 | + * |
|
| 313 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
| 314 | + * |
|
| 315 | + * The returned json object is created from an array in the following format: |
|
| 316 | + * array( |
|
| 317 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 318 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 319 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
| 320 | + * args that might be included in here) |
|
| 321 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
| 322 | + * ) |
|
| 323 | + */ |
|
| 324 | + protected function _return_json($data) |
|
| 325 | + { |
|
| 326 | + $json = array( |
|
| 327 | + 'notices' => EE_Error::get_notices(), |
|
| 328 | + 'data' => $data, |
|
| 329 | + 'isEEajax' => true |
|
| 330 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 331 | + ); |
|
| 332 | 332 | |
| 333 | 333 | |
| 334 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 335 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 336 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 337 | - } |
|
| 338 | - echo wp_json_encode($json); |
|
| 339 | - exit(); |
|
| 340 | - } |
|
| 334 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 335 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 336 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 337 | + } |
|
| 338 | + echo wp_json_encode($json); |
|
| 339 | + exit(); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Gets the job step response which was done during the enqueuing of scripts |
|
| 344 | - * |
|
| 345 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 346 | - */ |
|
| 347 | - public function job_step_response() |
|
| 348 | - { |
|
| 349 | - return $this->_job_step_response; |
|
| 350 | - } |
|
| 342 | + /** |
|
| 343 | + * Gets the job step response which was done during the enqueuing of scripts |
|
| 344 | + * |
|
| 345 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
| 346 | + */ |
|
| 347 | + public function job_step_response() |
|
| 348 | + { |
|
| 349 | + return $this->_job_step_response; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Gets the batch request type indicated in the $_REQUEST |
|
| 354 | - * |
|
| 355 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 356 | - */ |
|
| 357 | - public function batch_request_type() |
|
| 358 | - { |
|
| 359 | - if ($this->_batch_request_type === null) { |
|
| 360 | - if (isset($_GET['batch'])) { |
|
| 361 | - if ($_GET['batch'] == self::batch_job) { |
|
| 362 | - $this->_batch_request_type = self::batch_job; |
|
| 363 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 364 | - $this->_batch_request_type = self::batch_file_job; |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
| 368 | - if ($this->_batch_request_type === null) { |
|
| 369 | - $this->_batch_request_type = self::batch_not_job; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return $this->_batch_request_type; |
|
| 373 | - } |
|
| 352 | + /** |
|
| 353 | + * Gets the batch request type indicated in the $_REQUEST |
|
| 354 | + * |
|
| 355 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
| 356 | + */ |
|
| 357 | + public function batch_request_type() |
|
| 358 | + { |
|
| 359 | + if ($this->_batch_request_type === null) { |
|
| 360 | + if (isset($_GET['batch'])) { |
|
| 361 | + if ($_GET['batch'] == self::batch_job) { |
|
| 362 | + $this->_batch_request_type = self::batch_job; |
|
| 363 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
| 364 | + $this->_batch_request_type = self::batch_file_job; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
| 368 | + if ($this->_batch_request_type === null) { |
|
| 369 | + $this->_batch_request_type = self::batch_not_job; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return $this->_batch_request_type; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Unnecessary |
|
| 377 | - * |
|
| 378 | - * @param type $WP |
|
| 379 | - */ |
|
| 380 | - public function run($WP) |
|
| 381 | - { |
|
| 382 | - } |
|
| 375 | + /** |
|
| 376 | + * Unnecessary |
|
| 377 | + * |
|
| 378 | + * @param type $WP |
|
| 379 | + */ |
|
| 380 | + public function run($WP) |
|
| 381 | + { |
|
| 382 | + } |
|
| 383 | 383 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | protected function getLoader() |
| 114 | 114 | { |
| 115 | - if (!$this->loader instanceof LoaderInterface) { |
|
| 115 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
| 116 | 116 | $this->loader = LoaderFactory::getLoader(); |
| 117 | 117 | } |
| 118 | 118 | return $this->loader; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 150 | 150 | wp_enqueue_script( |
| 151 | 151 | 'batch_runner_init', |
| 152 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
| 152 | + BATCH_URL.'assets/batch_runner_init.js', |
|
| 153 | 153 | array('batch_runner'), |
| 154 | 154 | EVENT_ESPRESSO_VERSION, |
| 155 | 155 | true |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 174 | 174 | wp_enqueue_script( |
| 175 | 175 | 'batch_file_runner_init', |
| 176 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
| 176 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
| 177 | 177 | array('batch_runner'), |
| 178 | 178 | EVENT_ESPRESSO_VERSION, |
| 179 | 179 | true |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | array( |
| 186 | 186 | 'download_and_redirecting' => sprintf( |
| 187 | 187 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
| 188 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
| 188 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
| 189 | 189 | '</a>' |
| 190 | 190 | ), |
| 191 | 191 | 'return_url' => $_REQUEST['return_url'], |
@@ -204,18 +204,18 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | wp_register_script( |
| 206 | 206 | 'progress_bar', |
| 207 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
| 207 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
| 208 | 208 | array('jquery') |
| 209 | 209 | ); |
| 210 | 210 | wp_enqueue_style( |
| 211 | 211 | 'progress_bar', |
| 212 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
| 212 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
| 213 | 213 | array(), |
| 214 | 214 | EVENT_ESPRESSO_VERSION |
| 215 | 215 | ); |
| 216 | 216 | wp_enqueue_script( |
| 217 | 217 | 'batch_runner', |
| 218 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
| 218 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
| 219 | 219 | array('progress_bar') |
| 220 | 220 | ); |
| 221 | 221 | // just copy the bits of EE admin's eei18n that we need in the JS |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | public function override_template($template) |
| 251 | 251 | { |
| 252 | 252 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
| 253 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
| 253 | + return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html'; |
|
| 254 | 254 | } |
| 255 | 255 | return $template; |
| 256 | 256 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | public function show_admin_page() |
| 278 | 278 | { |
| 279 | 279 | echo EEH_Template::locate_template( |
| 280 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
| 280 | + EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', |
|
| 281 | 281 | array('batch_request_type' => $this->batch_request_type()) |
| 282 | 282 | ); |
| 283 | 283 | } |
@@ -25,215 +25,215 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class BatchRequestProcessor |
| 27 | 27 | { |
| 28 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 29 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 30 | - /** |
|
| 31 | - * Current job's ID (if assigned) |
|
| 32 | - * |
|
| 33 | - * @var string|null |
|
| 34 | - */ |
|
| 35 | - protected $_job_id; |
|
| 28 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 29 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 30 | + /** |
|
| 31 | + * Current job's ID (if assigned) |
|
| 32 | + * |
|
| 33 | + * @var string|null |
|
| 34 | + */ |
|
| 35 | + protected $_job_id; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Current job's parameters |
|
| 39 | - * |
|
| 40 | - * @var JobParameters|null |
|
| 41 | - */ |
|
| 42 | - protected $_job_parameters; |
|
| 43 | - /** |
|
| 44 | - * @var LoaderInterface |
|
| 45 | - */ |
|
| 46 | - private $loader; |
|
| 37 | + /** |
|
| 38 | + * Current job's parameters |
|
| 39 | + * |
|
| 40 | + * @var JobParameters|null |
|
| 41 | + */ |
|
| 42 | + protected $_job_parameters; |
|
| 43 | + /** |
|
| 44 | + * @var LoaderInterface |
|
| 45 | + */ |
|
| 46 | + private $loader; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * BatchRequestProcessor constructor. |
|
| 50 | - * @param LoaderInterface $loader |
|
| 51 | - */ |
|
| 52 | - public function __construct(LoaderInterface $loader) |
|
| 53 | - { |
|
| 54 | - $this->loader = $loader; |
|
| 55 | - } |
|
| 56 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 57 | - /** |
|
| 58 | - * Creates a job for the specified batch handler class (which should be autoloaded) |
|
| 59 | - * and the specified request data |
|
| 60 | - * |
|
| 61 | - * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
| 62 | - * @param array $request_data to be used by the batch job handler |
|
| 63 | - * @return JobStepResponse |
|
| 64 | - */ |
|
| 65 | - public function create_job($batch_job_handler_class, $request_data) |
|
| 66 | - { |
|
| 67 | - try { |
|
| 68 | - $this->_job_id = wp_generate_password(15, false); |
|
| 69 | - $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
| 70 | - $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
| 71 | - $response = $obj->create_job($this->_job_parameters); |
|
| 72 | - if (! $response instanceof JobStepResponse) { |
|
| 73 | - throw new BatchRequestException( |
|
| 74 | - sprintf( |
|
| 75 | - __( |
|
| 76 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - wp_json_encode($request_data) |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - $success = $this->_job_parameters->save(true); |
|
| 84 | - if (! $success) { |
|
| 85 | - throw new BatchRequestException( |
|
| 86 | - sprintf( |
|
| 87 | - __( |
|
| 88 | - 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
| 89 | - 'event_espresso' |
|
| 90 | - ), |
|
| 91 | - $this->_job_id, |
|
| 92 | - wp_json_encode($request_data) |
|
| 93 | - ) |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - } catch (\Exception $e) { |
|
| 97 | - $response = $this->_get_error_response($e, 'create_job'); |
|
| 98 | - } |
|
| 99 | - return $response; |
|
| 100 | - } |
|
| 48 | + /** |
|
| 49 | + * BatchRequestProcessor constructor. |
|
| 50 | + * @param LoaderInterface $loader |
|
| 51 | + */ |
|
| 52 | + public function __construct(LoaderInterface $loader) |
|
| 53 | + { |
|
| 54 | + $this->loader = $loader; |
|
| 55 | + } |
|
| 56 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 57 | + /** |
|
| 58 | + * Creates a job for the specified batch handler class (which should be autoloaded) |
|
| 59 | + * and the specified request data |
|
| 60 | + * |
|
| 61 | + * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
| 62 | + * @param array $request_data to be used by the batch job handler |
|
| 63 | + * @return JobStepResponse |
|
| 64 | + */ |
|
| 65 | + public function create_job($batch_job_handler_class, $request_data) |
|
| 66 | + { |
|
| 67 | + try { |
|
| 68 | + $this->_job_id = wp_generate_password(15, false); |
|
| 69 | + $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
| 70 | + $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
| 71 | + $response = $obj->create_job($this->_job_parameters); |
|
| 72 | + if (! $response instanceof JobStepResponse) { |
|
| 73 | + throw new BatchRequestException( |
|
| 74 | + sprintf( |
|
| 75 | + __( |
|
| 76 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + wp_json_encode($request_data) |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + $success = $this->_job_parameters->save(true); |
|
| 84 | + if (! $success) { |
|
| 85 | + throw new BatchRequestException( |
|
| 86 | + sprintf( |
|
| 87 | + __( |
|
| 88 | + 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
| 89 | + 'event_espresso' |
|
| 90 | + ), |
|
| 91 | + $this->_job_id, |
|
| 92 | + wp_json_encode($request_data) |
|
| 93 | + ) |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + } catch (\Exception $e) { |
|
| 97 | + $response = $this->_get_error_response($e, 'create_job'); |
|
| 98 | + } |
|
| 99 | + return $response; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Retrieves the job's arguments |
|
| 105 | - * |
|
| 106 | - * @param string $job_id |
|
| 107 | - * @param int $batch_size |
|
| 108 | - * @return JobStepResponse |
|
| 109 | - */ |
|
| 110 | - public function continue_job($job_id, $batch_size = 50) |
|
| 111 | - { |
|
| 112 | - try { |
|
| 113 | - $this->_job_id = $job_id; |
|
| 114 | - $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 115 | - // get the corresponding WordPress option for the job |
|
| 116 | - $this->_job_parameters = JobParameters::load($this->_job_id); |
|
| 117 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
| 118 | - // continue it |
|
| 119 | - $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
| 120 | - if (! $response instanceof JobStepResponse) { |
|
| 121 | - throw new BatchRequestException( |
|
| 122 | - sprintf( |
|
| 123 | - __( |
|
| 124 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 125 | - 'event_espresso' |
|
| 126 | - ), |
|
| 127 | - $this->_job_id |
|
| 128 | - ) |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - $this->_job_parameters->save(); |
|
| 132 | - } catch (\Exception $e) { |
|
| 133 | - $response = $this->_get_error_response($e, 'continue_job'); |
|
| 134 | - } |
|
| 135 | - return $response; |
|
| 136 | - } |
|
| 103 | + /** |
|
| 104 | + * Retrieves the job's arguments |
|
| 105 | + * |
|
| 106 | + * @param string $job_id |
|
| 107 | + * @param int $batch_size |
|
| 108 | + * @return JobStepResponse |
|
| 109 | + */ |
|
| 110 | + public function continue_job($job_id, $batch_size = 50) |
|
| 111 | + { |
|
| 112 | + try { |
|
| 113 | + $this->_job_id = $job_id; |
|
| 114 | + $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 115 | + // get the corresponding WordPress option for the job |
|
| 116 | + $this->_job_parameters = JobParameters::load($this->_job_id); |
|
| 117 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
| 118 | + // continue it |
|
| 119 | + $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
| 120 | + if (! $response instanceof JobStepResponse) { |
|
| 121 | + throw new BatchRequestException( |
|
| 122 | + sprintf( |
|
| 123 | + __( |
|
| 124 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 125 | + 'event_espresso' |
|
| 126 | + ), |
|
| 127 | + $this->_job_id |
|
| 128 | + ) |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + $this->_job_parameters->save(); |
|
| 132 | + } catch (\Exception $e) { |
|
| 133 | + $response = $this->_get_error_response($e, 'continue_job'); |
|
| 134 | + } |
|
| 135 | + return $response; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Instantiates an object of type $classname, which implements |
|
| 141 | - * JobHandlerInterface |
|
| 142 | - * |
|
| 143 | - * @param string $classname |
|
| 144 | - * @return JobHandlerInterface |
|
| 145 | - * @throws BatchRequestException |
|
| 146 | - */ |
|
| 147 | - public function instantiate_batch_job_handler_from_classname($classname) |
|
| 148 | - { |
|
| 149 | - if (! class_exists($classname)) { |
|
| 150 | - throw new BatchRequestException( |
|
| 151 | - sprintf( |
|
| 152 | - __( |
|
| 153 | - 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
| 154 | - 'event_espresso' |
|
| 155 | - ), |
|
| 156 | - $classname |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - $obj = $this->loader->getNew($classname); |
|
| 161 | - if (! $obj instanceof JobHandlerInterface) { |
|
| 162 | - throw new BatchRequestException( |
|
| 163 | - sprintf( |
|
| 164 | - __( |
|
| 165 | - 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
| 166 | - 'event_espresso' |
|
| 167 | - ), |
|
| 168 | - $classname |
|
| 169 | - ) |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - return $obj; |
|
| 173 | - } |
|
| 139 | + /** |
|
| 140 | + * Instantiates an object of type $classname, which implements |
|
| 141 | + * JobHandlerInterface |
|
| 142 | + * |
|
| 143 | + * @param string $classname |
|
| 144 | + * @return JobHandlerInterface |
|
| 145 | + * @throws BatchRequestException |
|
| 146 | + */ |
|
| 147 | + public function instantiate_batch_job_handler_from_classname($classname) |
|
| 148 | + { |
|
| 149 | + if (! class_exists($classname)) { |
|
| 150 | + throw new BatchRequestException( |
|
| 151 | + sprintf( |
|
| 152 | + __( |
|
| 153 | + 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
| 154 | + 'event_espresso' |
|
| 155 | + ), |
|
| 156 | + $classname |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + $obj = $this->loader->getNew($classname); |
|
| 161 | + if (! $obj instanceof JobHandlerInterface) { |
|
| 162 | + throw new BatchRequestException( |
|
| 163 | + sprintf( |
|
| 164 | + __( |
|
| 165 | + 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
| 166 | + 'event_espresso' |
|
| 167 | + ), |
|
| 168 | + $classname |
|
| 169 | + ) |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + return $obj; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Forces a job to be cleaned up |
|
| 178 | - * |
|
| 179 | - * @param string $job_id |
|
| 180 | - * @return JobStepResponse |
|
| 181 | - * @throws BatchRequestException |
|
| 182 | - */ |
|
| 183 | - public function cleanup_job($job_id) |
|
| 184 | - { |
|
| 185 | - try { |
|
| 186 | - $this->_job_id = $job_id; |
|
| 187 | - $job_parameters = JobParameters::load($this->_job_id); |
|
| 188 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
| 189 | - // continue it |
|
| 190 | - $response = $handler_obj->cleanup_job($job_parameters); |
|
| 191 | - if (! $response instanceof JobStepResponse) { |
|
| 192 | - throw new BatchRequestException( |
|
| 193 | - sprintf( |
|
| 194 | - __( |
|
| 195 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 196 | - 'event_espresso' |
|
| 197 | - ), |
|
| 198 | - $this->_job_id |
|
| 199 | - ) |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
| 203 | - $job_parameters->delete(); |
|
| 204 | - return $response; |
|
| 205 | - } catch (\Exception $e) { |
|
| 206 | - $response = $this->_get_error_response($e, 'cleanup_job'); |
|
| 207 | - } |
|
| 208 | - return $response; |
|
| 209 | - } |
|
| 176 | + /** |
|
| 177 | + * Forces a job to be cleaned up |
|
| 178 | + * |
|
| 179 | + * @param string $job_id |
|
| 180 | + * @return JobStepResponse |
|
| 181 | + * @throws BatchRequestException |
|
| 182 | + */ |
|
| 183 | + public function cleanup_job($job_id) |
|
| 184 | + { |
|
| 185 | + try { |
|
| 186 | + $this->_job_id = $job_id; |
|
| 187 | + $job_parameters = JobParameters::load($this->_job_id); |
|
| 188 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
| 189 | + // continue it |
|
| 190 | + $response = $handler_obj->cleanup_job($job_parameters); |
|
| 191 | + if (! $response instanceof JobStepResponse) { |
|
| 192 | + throw new BatchRequestException( |
|
| 193 | + sprintf( |
|
| 194 | + __( |
|
| 195 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 196 | + 'event_espresso' |
|
| 197 | + ), |
|
| 198 | + $this->_job_id |
|
| 199 | + ) |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
| 203 | + $job_parameters->delete(); |
|
| 204 | + return $response; |
|
| 205 | + } catch (\Exception $e) { |
|
| 206 | + $response = $this->_get_error_response($e, 'cleanup_job'); |
|
| 207 | + } |
|
| 208 | + return $response; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Creates a valid JobStepResponse object from an exception and method name. |
|
| 214 | - * |
|
| 215 | - * @param \Exception $exception |
|
| 216 | - * @param string $method_name |
|
| 217 | - * @return JobStepResponse |
|
| 218 | - */ |
|
| 219 | - protected function _get_error_response(\Exception $exception, $method_name) |
|
| 220 | - { |
|
| 221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | - $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
|
| 223 | - } |
|
| 224 | - $this->_job_parameters->set_status(JobParameters::status_error); |
|
| 225 | - return new JobStepResponse( |
|
| 226 | - $this->_job_parameters, |
|
| 227 | - sprintf( |
|
| 228 | - __( |
|
| 229 | - 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
| 230 | - 'event_espresso' |
|
| 231 | - ), |
|
| 232 | - get_class($exception), |
|
| 233 | - 'BatchRunner::' . $method_name . '()', |
|
| 234 | - $exception->getMessage(), |
|
| 235 | - $exception->getTraceAsString() |
|
| 236 | - ) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 212 | + /** |
|
| 213 | + * Creates a valid JobStepResponse object from an exception and method name. |
|
| 214 | + * |
|
| 215 | + * @param \Exception $exception |
|
| 216 | + * @param string $method_name |
|
| 217 | + * @return JobStepResponse |
|
| 218 | + */ |
|
| 219 | + protected function _get_error_response(\Exception $exception, $method_name) |
|
| 220 | + { |
|
| 221 | + if (! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | + $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
|
| 223 | + } |
|
| 224 | + $this->_job_parameters->set_status(JobParameters::status_error); |
|
| 225 | + return new JobStepResponse( |
|
| 226 | + $this->_job_parameters, |
|
| 227 | + sprintf( |
|
| 228 | + __( |
|
| 229 | + 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
| 230 | + 'event_espresso' |
|
| 231 | + ), |
|
| 232 | + get_class($exception), |
|
| 233 | + 'BatchRunner::' . $method_name . '()', |
|
| 234 | + $exception->getMessage(), |
|
| 235 | + $exception->getTraceAsString() |
|
| 236 | + ) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | 239 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
| 70 | 70 | $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
| 71 | 71 | $response = $obj->create_job($this->_job_parameters); |
| 72 | - if (! $response instanceof JobStepResponse) { |
|
| 72 | + if ( ! $response instanceof JobStepResponse) { |
|
| 73 | 73 | throw new BatchRequestException( |
| 74 | 74 | sprintf( |
| 75 | 75 | __( |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | $success = $this->_job_parameters->save(true); |
| 84 | - if (! $success) { |
|
| 84 | + if ( ! $success) { |
|
| 85 | 85 | throw new BatchRequestException( |
| 86 | 86 | sprintf( |
| 87 | 87 | __( |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
| 118 | 118 | // continue it |
| 119 | 119 | $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
| 120 | - if (! $response instanceof JobStepResponse) { |
|
| 120 | + if ( ! $response instanceof JobStepResponse) { |
|
| 121 | 121 | throw new BatchRequestException( |
| 122 | 122 | sprintf( |
| 123 | 123 | __( |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function instantiate_batch_job_handler_from_classname($classname) |
| 148 | 148 | { |
| 149 | - if (! class_exists($classname)) { |
|
| 149 | + if ( ! class_exists($classname)) { |
|
| 150 | 150 | throw new BatchRequestException( |
| 151 | 151 | sprintf( |
| 152 | 152 | __( |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | ); |
| 159 | 159 | } |
| 160 | 160 | $obj = $this->loader->getNew($classname); |
| 161 | - if (! $obj instanceof JobHandlerInterface) { |
|
| 161 | + if ( ! $obj instanceof JobHandlerInterface) { |
|
| 162 | 162 | throw new BatchRequestException( |
| 163 | 163 | sprintf( |
| 164 | 164 | __( |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
| 189 | 189 | // continue it |
| 190 | 190 | $response = $handler_obj->cleanup_job($job_parameters); |
| 191 | - if (! $response instanceof JobStepResponse) { |
|
| 191 | + if ( ! $response instanceof JobStepResponse) { |
|
| 192 | 192 | throw new BatchRequestException( |
| 193 | 193 | sprintf( |
| 194 | 194 | __( |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | protected function _get_error_response(\Exception $exception, $method_name) |
| 220 | 220 | { |
| 221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
| 221 | + if ( ! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | 222 | $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
| 223 | 223 | } |
| 224 | 224 | $this->_job_parameters->set_status(JobParameters::status_error); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | 'event_espresso' |
| 231 | 231 | ), |
| 232 | 232 | get_class($exception), |
| 233 | - 'BatchRunner::' . $method_name . '()', |
|
| 233 | + 'BatchRunner::'.$method_name.'()', |
|
| 234 | 234 | $exception->getMessage(), |
| 235 | 235 | $exception->getTraceAsString() |
| 236 | 236 | ) |
@@ -10,11 +10,11 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class EE_File_Input_Display_Strategy extends EE_Text_Input_Display_Strategy |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Override's parent to just set the type. May someday support other arguments. |
|
| 15 | - */ |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - parent::__construct('file'); |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * Override's parent to just set the type. May someday support other arguments. |
|
| 15 | + */ |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + parent::__construct('file'); |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -15,37 +15,37 @@ |
||
| 15 | 15 | interface FileSubmissionInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function getName(); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function getType(); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return int |
|
| 30 | - */ |
|
| 31 | - public function getSize(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function getTmpFile(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Should just return the filename. |
|
| 40 | - * @since $VID:$ |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function __toString(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function getErrorCode(); |
|
| 18 | + /** |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function getName(); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function getType(); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return int |
|
| 30 | + */ |
|
| 31 | + public function getSize(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function getTmpFile(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Should just return the filename. |
|
| 40 | + * @since $VID:$ |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function __toString(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function getErrorCode(); |
|
| 49 | 49 | } |
| 50 | 50 | // End of file FileSubmissionInterface.php |
| 51 | 51 | // Location: EventEspresso\core\services\request\files/FileSubmissionInterface.php |
@@ -19,86 +19,86 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class EE_File_Input extends EE_Form_Input_Base |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $allowed_file_extensions; |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $allowed_file_extensions; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $allowed_mime_types; |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $allowed_mime_types; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param array $options |
|
| 34 | - * @throws InvalidArgumentException |
|
| 35 | - */ |
|
| 36 | - public function __construct($options = array()) |
|
| 37 | - { |
|
| 38 | - if (isset($options['allowed_file_extensions'])) { |
|
| 39 | - $this->allowed_file_extensions = (array) $options['allowed_file_extensions']; |
|
| 40 | - } else { |
|
| 41 | - $this->allowed_file_extensions = ['csv']; |
|
| 42 | - } |
|
| 43 | - if (isset($options['allowed_mime_types'])) { |
|
| 44 | - $this->allowed_mime_types = (array) $options['allowed_file_extensions']; |
|
| 45 | - } else { |
|
| 46 | - $this->allowed_mime_types = ['text/csv']; |
|
| 47 | - } |
|
| 32 | + /** |
|
| 33 | + * @param array $options |
|
| 34 | + * @throws InvalidArgumentException |
|
| 35 | + */ |
|
| 36 | + public function __construct($options = array()) |
|
| 37 | + { |
|
| 38 | + if (isset($options['allowed_file_extensions'])) { |
|
| 39 | + $this->allowed_file_extensions = (array) $options['allowed_file_extensions']; |
|
| 40 | + } else { |
|
| 41 | + $this->allowed_file_extensions = ['csv']; |
|
| 42 | + } |
|
| 43 | + if (isset($options['allowed_mime_types'])) { |
|
| 44 | + $this->allowed_mime_types = (array) $options['allowed_file_extensions']; |
|
| 45 | + } else { |
|
| 46 | + $this->allowed_mime_types = ['text/csv']; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
| 50 | - $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
| 51 | - $this->add_validation_strategy( |
|
| 52 | - new EE_Text_Validation_Strategy( |
|
| 53 | - sprintf( |
|
| 54 | - // translators: %1$s is a list of allowed file extensions. |
|
| 55 | - esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
| 56 | - implode(', ', $this->allowed_file_extensions) |
|
| 57 | - ), |
|
| 58 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
| 59 | - ) |
|
| 60 | - ); |
|
| 61 | - parent::__construct($options); |
|
| 49 | + $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
| 50 | + $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
| 51 | + $this->add_validation_strategy( |
|
| 52 | + new EE_Text_Validation_Strategy( |
|
| 53 | + sprintf( |
|
| 54 | + // translators: %1$s is a list of allowed file extensions. |
|
| 55 | + esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
| 56 | + implode(', ', $this->allowed_file_extensions) |
|
| 57 | + ), |
|
| 58 | + '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
| 59 | + ) |
|
| 60 | + ); |
|
| 61 | + parent::__construct($options); |
|
| 62 | 62 | |
| 63 | 63 | // It would be great to add this HTML attribute, but jQuery validate chokes on it. |
| 64 | - $this->set_other_html_attributes( |
|
| 65 | - $this->other_html_attributes() |
|
| 66 | - . ' extension="' |
|
| 67 | - . implode( |
|
| 68 | - ',', |
|
| 69 | - $this->allowed_file_extensions |
|
| 70 | - ) |
|
| 71 | - . '"' |
|
| 72 | - ); |
|
| 73 | - } |
|
| 64 | + $this->set_other_html_attributes( |
|
| 65 | + $this->other_html_attributes() |
|
| 66 | + . ' extension="' |
|
| 67 | + . implode( |
|
| 68 | + ',', |
|
| 69 | + $this->allowed_file_extensions |
|
| 70 | + ) |
|
| 71 | + . '"' |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for |
|
| 77 | - * this input. |
|
| 78 | - * @since $VID:$ |
|
| 79 | - * @param array $req_data |
|
| 80 | - * @return FileSubmissionInterface |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws InvalidDataTypeException |
|
| 83 | - * @throws InvalidInterfaceException |
|
| 84 | - */ |
|
| 85 | - public function find_form_data_for_this_section($req_data) |
|
| 86 | - { |
|
| 87 | - // ignore $req_data. Files are in the files data handler. |
|
| 88 | - $fileDataHandler = LoaderFactory::getLoader()->getShared( |
|
| 89 | - 'EventEspresso\core\services\request\files\FilesDataHandler' |
|
| 90 | - ); |
|
| 91 | - return $fileDataHandler->getFileObject($this->html_name()); |
|
| 92 | - } |
|
| 75 | + /** |
|
| 76 | + * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for |
|
| 77 | + * this input. |
|
| 78 | + * @since $VID:$ |
|
| 79 | + * @param array $req_data |
|
| 80 | + * @return FileSubmissionInterface |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws InvalidDataTypeException |
|
| 83 | + * @throws InvalidInterfaceException |
|
| 84 | + */ |
|
| 85 | + public function find_form_data_for_this_section($req_data) |
|
| 86 | + { |
|
| 87 | + // ignore $req_data. Files are in the files data handler. |
|
| 88 | + $fileDataHandler = LoaderFactory::getLoader()->getShared( |
|
| 89 | + 'EventEspresso\core\services\request\files\FilesDataHandler' |
|
| 90 | + ); |
|
| 91 | + return $fileDataHandler->getFileObject($this->html_name()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Don't transform the file submission object into a string, thanks. |
|
| 96 | - * |
|
| 97 | - * @param string $value |
|
| 98 | - * @return null|string |
|
| 99 | - */ |
|
| 100 | - protected function _sanitize($value) |
|
| 101 | - { |
|
| 102 | - return $value; |
|
| 103 | - } |
|
| 94 | + /** |
|
| 95 | + * Don't transform the file submission object into a string, thanks. |
|
| 96 | + * |
|
| 97 | + * @param string $value |
|
| 98 | + * @return null|string |
|
| 99 | + */ |
|
| 100 | + protected function _sanitize($value) |
|
| 101 | + { |
|
| 102 | + return $value; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
| 56 | 56 | implode(', ', $this->allowed_file_extensions) |
| 57 | 57 | ), |
| 58 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
| 58 | + '~.*\.('.implode('|', $this->allowed_file_extensions).')$~' |
|
| 59 | 59 | ) |
| 60 | 60 | ); |
| 61 | 61 | parent::__construct($options); |
@@ -29,639 +29,639 @@ |
||
| 29 | 29 | abstract class FormHandler implements FormHandlerInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | - */ |
|
| 35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | - */ |
|
| 40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | - */ |
|
| 45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | - */ |
|
| 50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * if set to false, then this form has no displayable content, |
|
| 54 | - * and will only be used for processing data sent passed via GET or POST |
|
| 55 | - * defaults to true ( ie: form has displayable content ) |
|
| 56 | - * |
|
| 57 | - * @var boolean $displayable |
|
| 58 | - */ |
|
| 59 | - private $displayable = true; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string $form_name |
|
| 63 | - */ |
|
| 64 | - private $form_name; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var string $admin_name |
|
| 68 | - */ |
|
| 69 | - private $admin_name; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string $slug |
|
| 73 | - */ |
|
| 74 | - private $slug; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var string $submit_btn_text |
|
| 78 | - */ |
|
| 79 | - private $submit_btn_text; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var string $form_action |
|
| 83 | - */ |
|
| 84 | - private $form_action; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * form params in key value pairs |
|
| 88 | - * can be added to form action URL or as hidden inputs |
|
| 89 | - * |
|
| 90 | - * @var array $form_args |
|
| 91 | - */ |
|
| 92 | - private $form_args = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * value of one of the string constant above |
|
| 96 | - * |
|
| 97 | - * @var string $form_config |
|
| 98 | - */ |
|
| 99 | - private $form_config; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * whether or not the form was determined to be invalid |
|
| 103 | - * |
|
| 104 | - * @var boolean $form_has_errors |
|
| 105 | - */ |
|
| 106 | - private $form_has_errors; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * the absolute top level form section being used on the page |
|
| 110 | - * |
|
| 111 | - * @var EE_Form_Section_Proper $form |
|
| 112 | - */ |
|
| 113 | - private $form; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var EE_Registry $registry |
|
| 117 | - */ |
|
| 118 | - protected $registry; |
|
| 119 | - |
|
| 120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | - /** |
|
| 122 | - * Form constructor. |
|
| 123 | - * |
|
| 124 | - * @param string $form_name |
|
| 125 | - * @param string $admin_name |
|
| 126 | - * @param string $slug |
|
| 127 | - * @param string $form_action |
|
| 128 | - * @param string $form_config |
|
| 129 | - * @param EE_Registry $registry |
|
| 130 | - * @throws InvalidDataTypeException |
|
| 131 | - * @throws DomainException |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - */ |
|
| 134 | - public function __construct( |
|
| 135 | - $form_name, |
|
| 136 | - $admin_name, |
|
| 137 | - $slug, |
|
| 138 | - $form_action = '', |
|
| 139 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 140 | - EE_Registry $registry |
|
| 141 | - ) { |
|
| 142 | - $this->setFormName($form_name); |
|
| 143 | - $this->setAdminName($admin_name); |
|
| 144 | - $this->setSlug($slug); |
|
| 145 | - $this->setFormAction($form_action); |
|
| 146 | - $this->setFormConfig($form_config); |
|
| 147 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 148 | - $this->registry = $registry; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public static function getFormConfigConstants() |
|
| 156 | - { |
|
| 157 | - return array( |
|
| 158 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 159 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 160 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 161 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param bool $for_display |
|
| 168 | - * @return EE_Form_Section_Proper |
|
| 169 | - * @throws EE_Error |
|
| 170 | - * @throws LogicException |
|
| 171 | - */ |
|
| 172 | - public function form($for_display = false) |
|
| 173 | - { |
|
| 174 | - if (! $this->formIsValid()) { |
|
| 175 | - return null; |
|
| 176 | - } |
|
| 177 | - if ($for_display) { |
|
| 178 | - $form_config = $this->formConfig(); |
|
| 179 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 180 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 181 | - ) { |
|
| 182 | - $this->appendSubmitButton(); |
|
| 183 | - $this->clearFormButtonFloats(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - return $this->form; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return boolean |
|
| 192 | - * @throws LogicException |
|
| 193 | - */ |
|
| 194 | - public function formIsValid() |
|
| 195 | - { |
|
| 196 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - $form = apply_filters( |
|
| 200 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 201 | - $this->generate(), |
|
| 202 | - $this |
|
| 203 | - ); |
|
| 204 | - if ($this->verifyForm($form)) { |
|
| 205 | - $this->setForm($form); |
|
| 206 | - } |
|
| 207 | - return true; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param EE_Form_Section_Proper|null $form |
|
| 213 | - * @return bool |
|
| 214 | - * @throws LogicException |
|
| 215 | - */ |
|
| 216 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 217 | - { |
|
| 218 | - $form = $form !== null ? $form : $this->form; |
|
| 219 | - if ($form instanceof EE_Form_Section_Proper) { |
|
| 220 | - return true; |
|
| 221 | - } |
|
| 222 | - throw new LogicException( |
|
| 223 | - sprintf( |
|
| 224 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 225 | - $this->form_name, |
|
| 226 | - var_export($form, true) |
|
| 227 | - ) |
|
| 228 | - ); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param EE_Form_Section_Proper $form |
|
| 234 | - */ |
|
| 235 | - public function setForm(EE_Form_Section_Proper $form) |
|
| 236 | - { |
|
| 237 | - $this->form = $form; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @return boolean |
|
| 243 | - */ |
|
| 244 | - public function displayable() |
|
| 245 | - { |
|
| 246 | - return $this->displayable; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param boolean $displayable |
|
| 252 | - */ |
|
| 253 | - public function setDisplayable($displayable = false) |
|
| 254 | - { |
|
| 255 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * a public name for the form that can be displayed on the frontend of a site |
|
| 261 | - * |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function formName() |
|
| 265 | - { |
|
| 266 | - return $this->form_name; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @param string $form_name |
|
| 272 | - * @throws InvalidDataTypeException |
|
| 273 | - */ |
|
| 274 | - public function setFormName($form_name) |
|
| 275 | - { |
|
| 276 | - if (! is_string($form_name)) { |
|
| 277 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 278 | - } |
|
| 279 | - $this->form_name = $form_name; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * a public name for the form that can be displayed, but only in the admin |
|
| 285 | - * |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function adminName() |
|
| 289 | - { |
|
| 290 | - return $this->admin_name; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param string $admin_name |
|
| 296 | - * @throws InvalidDataTypeException |
|
| 297 | - */ |
|
| 298 | - public function setAdminName($admin_name) |
|
| 299 | - { |
|
| 300 | - if (! is_string($admin_name)) { |
|
| 301 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 302 | - } |
|
| 303 | - $this->admin_name = $admin_name; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * a URL friendly string that can be used for identifying the form |
|
| 309 | - * |
|
| 310 | - * @return string |
|
| 311 | - */ |
|
| 312 | - public function slug() |
|
| 313 | - { |
|
| 314 | - return $this->slug; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param string $slug |
|
| 320 | - * @throws InvalidDataTypeException |
|
| 321 | - */ |
|
| 322 | - public function setSlug($slug) |
|
| 323 | - { |
|
| 324 | - if (! is_string($slug)) { |
|
| 325 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 326 | - } |
|
| 327 | - $this->slug = $slug; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @return string |
|
| 333 | - */ |
|
| 334 | - public function submitBtnText() |
|
| 335 | - { |
|
| 336 | - return $this->submit_btn_text; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @param string $submit_btn_text |
|
| 342 | - * @throws InvalidDataTypeException |
|
| 343 | - * @throws InvalidArgumentException |
|
| 344 | - */ |
|
| 345 | - public function setSubmitBtnText($submit_btn_text) |
|
| 346 | - { |
|
| 347 | - if (! is_string($submit_btn_text)) { |
|
| 348 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 349 | - } |
|
| 350 | - if (empty($submit_btn_text)) { |
|
| 351 | - throw new InvalidArgumentException( |
|
| 352 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - $this->submit_btn_text = $submit_btn_text; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - public function formAction() |
|
| 363 | - { |
|
| 364 | - return ! empty($this->form_args) |
|
| 365 | - ? add_query_arg($this->form_args, $this->form_action) |
|
| 366 | - : $this->form_action; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @param string $form_action |
|
| 372 | - * @throws InvalidDataTypeException |
|
| 373 | - */ |
|
| 374 | - public function setFormAction($form_action) |
|
| 375 | - { |
|
| 376 | - if (! is_string($form_action)) { |
|
| 377 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 378 | - } |
|
| 379 | - $this->form_action = $form_action; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @param array $form_args |
|
| 385 | - * @throws InvalidDataTypeException |
|
| 386 | - * @throws InvalidArgumentException |
|
| 387 | - */ |
|
| 388 | - public function addFormActionArgs($form_args = array()) |
|
| 389 | - { |
|
| 390 | - if (is_object($form_args)) { |
|
| 391 | - throw new InvalidDataTypeException( |
|
| 392 | - '$form_args', |
|
| 393 | - $form_args, |
|
| 394 | - 'anything other than an object was expected.' |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - if (empty($form_args)) { |
|
| 398 | - throw new InvalidArgumentException( |
|
| 399 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 400 | - ); |
|
| 401 | - } |
|
| 402 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * @return string |
|
| 408 | - */ |
|
| 409 | - public function formConfig() |
|
| 410 | - { |
|
| 411 | - return $this->form_config; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param string $form_config |
|
| 417 | - * @throws DomainException |
|
| 418 | - */ |
|
| 419 | - public function setFormConfig($form_config) |
|
| 420 | - { |
|
| 421 | - if (! in_array( |
|
| 422 | - $form_config, |
|
| 423 | - array( |
|
| 424 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 425 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 426 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 427 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 428 | - ), |
|
| 429 | - true |
|
| 430 | - ) |
|
| 431 | - ) { |
|
| 432 | - throw new DomainException( |
|
| 433 | - sprintf( |
|
| 434 | - esc_html__( |
|
| 435 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ), |
|
| 438 | - $form_config |
|
| 439 | - ) |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - $this->form_config = $form_config; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * called after the form is instantiated |
|
| 448 | - * and used for performing any logic that needs to occur early |
|
| 449 | - * before any of the other methods are called. |
|
| 450 | - * returns true if everything is ok to proceed, |
|
| 451 | - * and false if no further form logic should be implemented |
|
| 452 | - * |
|
| 453 | - * @return boolean |
|
| 454 | - */ |
|
| 455 | - public function initialize() |
|
| 456 | - { |
|
| 457 | - $this->form_has_errors = EE_Error::has_error(true); |
|
| 458 | - return true; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * used for setting up css and js |
|
| 464 | - * |
|
| 465 | - * @return void |
|
| 466 | - * @throws LogicException |
|
| 467 | - * @throws EE_Error |
|
| 468 | - */ |
|
| 469 | - public function enqueueStylesAndScripts() |
|
| 470 | - { |
|
| 471 | - $this->form()->enqueue_js(); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * creates and returns the actual form |
|
| 477 | - * |
|
| 478 | - * @return EE_Form_Section_Proper |
|
| 479 | - */ |
|
| 480 | - abstract public function generate(); |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 485 | - * |
|
| 486 | - * @param string $text |
|
| 487 | - * @return EE_Submit_Input |
|
| 488 | - */ |
|
| 489 | - public function generateSubmitButton($text = '') |
|
| 490 | - { |
|
| 491 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 492 | - return new EE_Submit_Input( |
|
| 493 | - array( |
|
| 494 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 496 | - 'html_class' => 'ee-form-submit', |
|
| 497 | - 'html_label' => ' ', |
|
| 498 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 499 | - 'default' => $text, |
|
| 500 | - ) |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 507 | - * |
|
| 508 | - * @param string $text |
|
| 509 | - * @return void |
|
| 510 | - * @throws EE_Error |
|
| 511 | - */ |
|
| 512 | - public function appendSubmitButton($text = '') |
|
| 513 | - { |
|
| 514 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 515 | - return; |
|
| 516 | - } |
|
| 517 | - $this->form->add_subsections( |
|
| 518 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 519 | - null, |
|
| 520 | - false |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 527 | - * |
|
| 528 | - * @param string $text |
|
| 529 | - * @return EE_Submit_Input |
|
| 530 | - */ |
|
| 531 | - public function generateCancelButton($text = '') |
|
| 532 | - { |
|
| 533 | - $cancel_button = new EE_Submit_Input( |
|
| 534 | - array( |
|
| 535 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 536 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 537 | - 'html_class' => 'ee-cancel-form', |
|
| 538 | - 'html_label' => ' ', |
|
| 539 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 540 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 541 | - ) |
|
| 542 | - ); |
|
| 543 | - $cancel_button->set_button_css_attributes(false); |
|
| 544 | - return $cancel_button; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * appends a float clearing div onto end of form |
|
| 550 | - * |
|
| 551 | - * @return void |
|
| 552 | - * @throws EE_Error |
|
| 553 | - */ |
|
| 554 | - public function clearFormButtonFloats() |
|
| 555 | - { |
|
| 556 | - $this->form->add_subsections( |
|
| 557 | - array( |
|
| 558 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 559 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 560 | - ), |
|
| 561 | - ), |
|
| 562 | - null, |
|
| 563 | - false |
|
| 564 | - ); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 570 | - * returns a string of HTML that can be directly echoed in a template |
|
| 571 | - * |
|
| 572 | - * @return string |
|
| 573 | - * @throws \InvalidArgumentException |
|
| 574 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 575 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 576 | - * @throws LogicException |
|
| 577 | - * @throws EE_Error |
|
| 578 | - */ |
|
| 579 | - public function display() |
|
| 580 | - { |
|
| 581 | - $form_html = apply_filters( |
|
| 582 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 583 | - '' |
|
| 584 | - ); |
|
| 585 | - $form_config = $this->formConfig(); |
|
| 586 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 587 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 588 | - ) { |
|
| 589 | - $additional_props = $this->requiresMultipartEnctype() |
|
| 590 | - ? 'enctype="multipart/form-data"' |
|
| 591 | - : ''; |
|
| 592 | - $form_html .= $this->form()->form_open( |
|
| 593 | - $this->formAction(), |
|
| 594 | - 'POST', |
|
| 595 | - $additional_props |
|
| 596 | - ); |
|
| 597 | - } |
|
| 598 | - $form_html .= $this->form(true)->get_html(); |
|
| 599 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 600 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 601 | - ) { |
|
| 602 | - $form_html .= $this->form()->form_close(); |
|
| 603 | - } |
|
| 604 | - $form_html .= apply_filters( |
|
| 605 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 606 | - '' |
|
| 607 | - ); |
|
| 608 | - return $form_html; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 613 | - * @since $VID:$ |
|
| 614 | - * @return bool |
|
| 615 | - * @throws EE_Error |
|
| 616 | - */ |
|
| 617 | - public function requiresMultipartEnctype() |
|
| 618 | - { |
|
| 619 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 620 | - if ($input instanceof EE_File_Input) { |
|
| 621 | - return true; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - return false; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * handles processing the form submission |
|
| 630 | - * returns true or false depending on whether the form was processed successfully or not |
|
| 631 | - * |
|
| 632 | - * @param array $submitted_form_data |
|
| 633 | - * @return array |
|
| 634 | - * @throws \InvalidArgumentException |
|
| 635 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 636 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 637 | - * @throws EE_Error |
|
| 638 | - * @throws LogicException |
|
| 639 | - * @throws InvalidFormSubmissionException |
|
| 640 | - */ |
|
| 641 | - public function process($submitted_form_data = array()) |
|
| 642 | - { |
|
| 643 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 644 | - throw new InvalidFormSubmissionException($this->form_name); |
|
| 645 | - } |
|
| 646 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 647 | - if (! $this->form()->is_valid()) { |
|
| 648 | - throw new InvalidFormSubmissionException( |
|
| 649 | - $this->form_name, |
|
| 650 | - sprintf( |
|
| 651 | - esc_html__( |
|
| 652 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 653 | - 'event_espresso' |
|
| 654 | - ), |
|
| 655 | - $this->form_name, |
|
| 656 | - '<br />', |
|
| 657 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 658 | - ) |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - return apply_filters( |
|
| 662 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 663 | - $this->form()->valid_data(), |
|
| 664 | - $this |
|
| 665 | - ); |
|
| 666 | - } |
|
| 32 | + /** |
|
| 33 | + * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | + */ |
|
| 35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | + */ |
|
| 40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | + */ |
|
| 45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | + */ |
|
| 50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * if set to false, then this form has no displayable content, |
|
| 54 | + * and will only be used for processing data sent passed via GET or POST |
|
| 55 | + * defaults to true ( ie: form has displayable content ) |
|
| 56 | + * |
|
| 57 | + * @var boolean $displayable |
|
| 58 | + */ |
|
| 59 | + private $displayable = true; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string $form_name |
|
| 63 | + */ |
|
| 64 | + private $form_name; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var string $admin_name |
|
| 68 | + */ |
|
| 69 | + private $admin_name; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string $slug |
|
| 73 | + */ |
|
| 74 | + private $slug; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var string $submit_btn_text |
|
| 78 | + */ |
|
| 79 | + private $submit_btn_text; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var string $form_action |
|
| 83 | + */ |
|
| 84 | + private $form_action; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * form params in key value pairs |
|
| 88 | + * can be added to form action URL or as hidden inputs |
|
| 89 | + * |
|
| 90 | + * @var array $form_args |
|
| 91 | + */ |
|
| 92 | + private $form_args = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * value of one of the string constant above |
|
| 96 | + * |
|
| 97 | + * @var string $form_config |
|
| 98 | + */ |
|
| 99 | + private $form_config; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * whether or not the form was determined to be invalid |
|
| 103 | + * |
|
| 104 | + * @var boolean $form_has_errors |
|
| 105 | + */ |
|
| 106 | + private $form_has_errors; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * the absolute top level form section being used on the page |
|
| 110 | + * |
|
| 111 | + * @var EE_Form_Section_Proper $form |
|
| 112 | + */ |
|
| 113 | + private $form; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var EE_Registry $registry |
|
| 117 | + */ |
|
| 118 | + protected $registry; |
|
| 119 | + |
|
| 120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | + /** |
|
| 122 | + * Form constructor. |
|
| 123 | + * |
|
| 124 | + * @param string $form_name |
|
| 125 | + * @param string $admin_name |
|
| 126 | + * @param string $slug |
|
| 127 | + * @param string $form_action |
|
| 128 | + * @param string $form_config |
|
| 129 | + * @param EE_Registry $registry |
|
| 130 | + * @throws InvalidDataTypeException |
|
| 131 | + * @throws DomainException |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + */ |
|
| 134 | + public function __construct( |
|
| 135 | + $form_name, |
|
| 136 | + $admin_name, |
|
| 137 | + $slug, |
|
| 138 | + $form_action = '', |
|
| 139 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 140 | + EE_Registry $registry |
|
| 141 | + ) { |
|
| 142 | + $this->setFormName($form_name); |
|
| 143 | + $this->setAdminName($admin_name); |
|
| 144 | + $this->setSlug($slug); |
|
| 145 | + $this->setFormAction($form_action); |
|
| 146 | + $this->setFormConfig($form_config); |
|
| 147 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 148 | + $this->registry = $registry; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public static function getFormConfigConstants() |
|
| 156 | + { |
|
| 157 | + return array( |
|
| 158 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 159 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 160 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 161 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param bool $for_display |
|
| 168 | + * @return EE_Form_Section_Proper |
|
| 169 | + * @throws EE_Error |
|
| 170 | + * @throws LogicException |
|
| 171 | + */ |
|
| 172 | + public function form($for_display = false) |
|
| 173 | + { |
|
| 174 | + if (! $this->formIsValid()) { |
|
| 175 | + return null; |
|
| 176 | + } |
|
| 177 | + if ($for_display) { |
|
| 178 | + $form_config = $this->formConfig(); |
|
| 179 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 180 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 181 | + ) { |
|
| 182 | + $this->appendSubmitButton(); |
|
| 183 | + $this->clearFormButtonFloats(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + return $this->form; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return boolean |
|
| 192 | + * @throws LogicException |
|
| 193 | + */ |
|
| 194 | + public function formIsValid() |
|
| 195 | + { |
|
| 196 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + $form = apply_filters( |
|
| 200 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 201 | + $this->generate(), |
|
| 202 | + $this |
|
| 203 | + ); |
|
| 204 | + if ($this->verifyForm($form)) { |
|
| 205 | + $this->setForm($form); |
|
| 206 | + } |
|
| 207 | + return true; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param EE_Form_Section_Proper|null $form |
|
| 213 | + * @return bool |
|
| 214 | + * @throws LogicException |
|
| 215 | + */ |
|
| 216 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 217 | + { |
|
| 218 | + $form = $form !== null ? $form : $this->form; |
|
| 219 | + if ($form instanceof EE_Form_Section_Proper) { |
|
| 220 | + return true; |
|
| 221 | + } |
|
| 222 | + throw new LogicException( |
|
| 223 | + sprintf( |
|
| 224 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 225 | + $this->form_name, |
|
| 226 | + var_export($form, true) |
|
| 227 | + ) |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param EE_Form_Section_Proper $form |
|
| 234 | + */ |
|
| 235 | + public function setForm(EE_Form_Section_Proper $form) |
|
| 236 | + { |
|
| 237 | + $this->form = $form; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return boolean |
|
| 243 | + */ |
|
| 244 | + public function displayable() |
|
| 245 | + { |
|
| 246 | + return $this->displayable; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param boolean $displayable |
|
| 252 | + */ |
|
| 253 | + public function setDisplayable($displayable = false) |
|
| 254 | + { |
|
| 255 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * a public name for the form that can be displayed on the frontend of a site |
|
| 261 | + * |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function formName() |
|
| 265 | + { |
|
| 266 | + return $this->form_name; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @param string $form_name |
|
| 272 | + * @throws InvalidDataTypeException |
|
| 273 | + */ |
|
| 274 | + public function setFormName($form_name) |
|
| 275 | + { |
|
| 276 | + if (! is_string($form_name)) { |
|
| 277 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 278 | + } |
|
| 279 | + $this->form_name = $form_name; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * a public name for the form that can be displayed, but only in the admin |
|
| 285 | + * |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function adminName() |
|
| 289 | + { |
|
| 290 | + return $this->admin_name; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param string $admin_name |
|
| 296 | + * @throws InvalidDataTypeException |
|
| 297 | + */ |
|
| 298 | + public function setAdminName($admin_name) |
|
| 299 | + { |
|
| 300 | + if (! is_string($admin_name)) { |
|
| 301 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 302 | + } |
|
| 303 | + $this->admin_name = $admin_name; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * a URL friendly string that can be used for identifying the form |
|
| 309 | + * |
|
| 310 | + * @return string |
|
| 311 | + */ |
|
| 312 | + public function slug() |
|
| 313 | + { |
|
| 314 | + return $this->slug; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param string $slug |
|
| 320 | + * @throws InvalidDataTypeException |
|
| 321 | + */ |
|
| 322 | + public function setSlug($slug) |
|
| 323 | + { |
|
| 324 | + if (! is_string($slug)) { |
|
| 325 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 326 | + } |
|
| 327 | + $this->slug = $slug; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @return string |
|
| 333 | + */ |
|
| 334 | + public function submitBtnText() |
|
| 335 | + { |
|
| 336 | + return $this->submit_btn_text; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @param string $submit_btn_text |
|
| 342 | + * @throws InvalidDataTypeException |
|
| 343 | + * @throws InvalidArgumentException |
|
| 344 | + */ |
|
| 345 | + public function setSubmitBtnText($submit_btn_text) |
|
| 346 | + { |
|
| 347 | + if (! is_string($submit_btn_text)) { |
|
| 348 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 349 | + } |
|
| 350 | + if (empty($submit_btn_text)) { |
|
| 351 | + throw new InvalidArgumentException( |
|
| 352 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + $this->submit_btn_text = $submit_btn_text; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + public function formAction() |
|
| 363 | + { |
|
| 364 | + return ! empty($this->form_args) |
|
| 365 | + ? add_query_arg($this->form_args, $this->form_action) |
|
| 366 | + : $this->form_action; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @param string $form_action |
|
| 372 | + * @throws InvalidDataTypeException |
|
| 373 | + */ |
|
| 374 | + public function setFormAction($form_action) |
|
| 375 | + { |
|
| 376 | + if (! is_string($form_action)) { |
|
| 377 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 378 | + } |
|
| 379 | + $this->form_action = $form_action; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @param array $form_args |
|
| 385 | + * @throws InvalidDataTypeException |
|
| 386 | + * @throws InvalidArgumentException |
|
| 387 | + */ |
|
| 388 | + public function addFormActionArgs($form_args = array()) |
|
| 389 | + { |
|
| 390 | + if (is_object($form_args)) { |
|
| 391 | + throw new InvalidDataTypeException( |
|
| 392 | + '$form_args', |
|
| 393 | + $form_args, |
|
| 394 | + 'anything other than an object was expected.' |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + if (empty($form_args)) { |
|
| 398 | + throw new InvalidArgumentException( |
|
| 399 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 400 | + ); |
|
| 401 | + } |
|
| 402 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * @return string |
|
| 408 | + */ |
|
| 409 | + public function formConfig() |
|
| 410 | + { |
|
| 411 | + return $this->form_config; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param string $form_config |
|
| 417 | + * @throws DomainException |
|
| 418 | + */ |
|
| 419 | + public function setFormConfig($form_config) |
|
| 420 | + { |
|
| 421 | + if (! in_array( |
|
| 422 | + $form_config, |
|
| 423 | + array( |
|
| 424 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 425 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 426 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 427 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 428 | + ), |
|
| 429 | + true |
|
| 430 | + ) |
|
| 431 | + ) { |
|
| 432 | + throw new DomainException( |
|
| 433 | + sprintf( |
|
| 434 | + esc_html__( |
|
| 435 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ), |
|
| 438 | + $form_config |
|
| 439 | + ) |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + $this->form_config = $form_config; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * called after the form is instantiated |
|
| 448 | + * and used for performing any logic that needs to occur early |
|
| 449 | + * before any of the other methods are called. |
|
| 450 | + * returns true if everything is ok to proceed, |
|
| 451 | + * and false if no further form logic should be implemented |
|
| 452 | + * |
|
| 453 | + * @return boolean |
|
| 454 | + */ |
|
| 455 | + public function initialize() |
|
| 456 | + { |
|
| 457 | + $this->form_has_errors = EE_Error::has_error(true); |
|
| 458 | + return true; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * used for setting up css and js |
|
| 464 | + * |
|
| 465 | + * @return void |
|
| 466 | + * @throws LogicException |
|
| 467 | + * @throws EE_Error |
|
| 468 | + */ |
|
| 469 | + public function enqueueStylesAndScripts() |
|
| 470 | + { |
|
| 471 | + $this->form()->enqueue_js(); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * creates and returns the actual form |
|
| 477 | + * |
|
| 478 | + * @return EE_Form_Section_Proper |
|
| 479 | + */ |
|
| 480 | + abstract public function generate(); |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 485 | + * |
|
| 486 | + * @param string $text |
|
| 487 | + * @return EE_Submit_Input |
|
| 488 | + */ |
|
| 489 | + public function generateSubmitButton($text = '') |
|
| 490 | + { |
|
| 491 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 492 | + return new EE_Submit_Input( |
|
| 493 | + array( |
|
| 494 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 496 | + 'html_class' => 'ee-form-submit', |
|
| 497 | + 'html_label' => ' ', |
|
| 498 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 499 | + 'default' => $text, |
|
| 500 | + ) |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 507 | + * |
|
| 508 | + * @param string $text |
|
| 509 | + * @return void |
|
| 510 | + * @throws EE_Error |
|
| 511 | + */ |
|
| 512 | + public function appendSubmitButton($text = '') |
|
| 513 | + { |
|
| 514 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 515 | + return; |
|
| 516 | + } |
|
| 517 | + $this->form->add_subsections( |
|
| 518 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 519 | + null, |
|
| 520 | + false |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 527 | + * |
|
| 528 | + * @param string $text |
|
| 529 | + * @return EE_Submit_Input |
|
| 530 | + */ |
|
| 531 | + public function generateCancelButton($text = '') |
|
| 532 | + { |
|
| 533 | + $cancel_button = new EE_Submit_Input( |
|
| 534 | + array( |
|
| 535 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 536 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 537 | + 'html_class' => 'ee-cancel-form', |
|
| 538 | + 'html_label' => ' ', |
|
| 539 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 540 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 541 | + ) |
|
| 542 | + ); |
|
| 543 | + $cancel_button->set_button_css_attributes(false); |
|
| 544 | + return $cancel_button; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * appends a float clearing div onto end of form |
|
| 550 | + * |
|
| 551 | + * @return void |
|
| 552 | + * @throws EE_Error |
|
| 553 | + */ |
|
| 554 | + public function clearFormButtonFloats() |
|
| 555 | + { |
|
| 556 | + $this->form->add_subsections( |
|
| 557 | + array( |
|
| 558 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 559 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 560 | + ), |
|
| 561 | + ), |
|
| 562 | + null, |
|
| 563 | + false |
|
| 564 | + ); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 570 | + * returns a string of HTML that can be directly echoed in a template |
|
| 571 | + * |
|
| 572 | + * @return string |
|
| 573 | + * @throws \InvalidArgumentException |
|
| 574 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 575 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 576 | + * @throws LogicException |
|
| 577 | + * @throws EE_Error |
|
| 578 | + */ |
|
| 579 | + public function display() |
|
| 580 | + { |
|
| 581 | + $form_html = apply_filters( |
|
| 582 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 583 | + '' |
|
| 584 | + ); |
|
| 585 | + $form_config = $this->formConfig(); |
|
| 586 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 587 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 588 | + ) { |
|
| 589 | + $additional_props = $this->requiresMultipartEnctype() |
|
| 590 | + ? 'enctype="multipart/form-data"' |
|
| 591 | + : ''; |
|
| 592 | + $form_html .= $this->form()->form_open( |
|
| 593 | + $this->formAction(), |
|
| 594 | + 'POST', |
|
| 595 | + $additional_props |
|
| 596 | + ); |
|
| 597 | + } |
|
| 598 | + $form_html .= $this->form(true)->get_html(); |
|
| 599 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 600 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 601 | + ) { |
|
| 602 | + $form_html .= $this->form()->form_close(); |
|
| 603 | + } |
|
| 604 | + $form_html .= apply_filters( |
|
| 605 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 606 | + '' |
|
| 607 | + ); |
|
| 608 | + return $form_html; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 613 | + * @since $VID:$ |
|
| 614 | + * @return bool |
|
| 615 | + * @throws EE_Error |
|
| 616 | + */ |
|
| 617 | + public function requiresMultipartEnctype() |
|
| 618 | + { |
|
| 619 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 620 | + if ($input instanceof EE_File_Input) { |
|
| 621 | + return true; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + return false; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * handles processing the form submission |
|
| 630 | + * returns true or false depending on whether the form was processed successfully or not |
|
| 631 | + * |
|
| 632 | + * @param array $submitted_form_data |
|
| 633 | + * @return array |
|
| 634 | + * @throws \InvalidArgumentException |
|
| 635 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 636 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 637 | + * @throws EE_Error |
|
| 638 | + * @throws LogicException |
|
| 639 | + * @throws InvalidFormSubmissionException |
|
| 640 | + */ |
|
| 641 | + public function process($submitted_form_data = array()) |
|
| 642 | + { |
|
| 643 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 644 | + throw new InvalidFormSubmissionException($this->form_name); |
|
| 645 | + } |
|
| 646 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 647 | + if (! $this->form()->is_valid()) { |
|
| 648 | + throw new InvalidFormSubmissionException( |
|
| 649 | + $this->form_name, |
|
| 650 | + sprintf( |
|
| 651 | + esc_html__( |
|
| 652 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 653 | + 'event_espresso' |
|
| 654 | + ), |
|
| 655 | + $this->form_name, |
|
| 656 | + '<br />', |
|
| 657 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 658 | + ) |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + return apply_filters( |
|
| 662 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 663 | + $this->form()->valid_data(), |
|
| 664 | + $this |
|
| 665 | + ); |
|
| 666 | + } |
|
| 667 | 667 | } |
@@ -13,40 +13,40 @@ |
||
| 13 | 13 | class EE_File_Normalization extends EE_Normalization_Strategy_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Keep in mind $value_to_normalize should be a FileSubmissionInterface or null, so this shouldn't really do |
|
| 18 | - * much (other than NOT convert it to a string or something). |
|
| 19 | - * @param string $value_to_normalize |
|
| 20 | - * @return FileSubmissionInterface |
|
| 21 | - */ |
|
| 22 | - public function normalize($value_to_normalize) |
|
| 23 | - { |
|
| 24 | - if ($value_to_normalize instanceof FileSubmissionInterface || is_null($value_to_normalize)) { |
|
| 25 | - return $value_to_normalize; |
|
| 26 | - } else { |
|
| 27 | - throw new EE_Validation_Error( |
|
| 28 | - esc_html__('The file input has an invalid format.', 'event_espresso') |
|
| 29 | - ); |
|
| 30 | - } |
|
| 31 | - } |
|
| 16 | + /** |
|
| 17 | + * Keep in mind $value_to_normalize should be a FileSubmissionInterface or null, so this shouldn't really do |
|
| 18 | + * much (other than NOT convert it to a string or something). |
|
| 19 | + * @param string $value_to_normalize |
|
| 20 | + * @return FileSubmissionInterface |
|
| 21 | + */ |
|
| 22 | + public function normalize($value_to_normalize) |
|
| 23 | + { |
|
| 24 | + if ($value_to_normalize instanceof FileSubmissionInterface || is_null($value_to_normalize)) { |
|
| 25 | + return $value_to_normalize; |
|
| 26 | + } else { |
|
| 27 | + throw new EE_Validation_Error( |
|
| 28 | + esc_html__('The file input has an invalid format.', 'event_espresso') |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * This may be called prematurely on submitted data, so we actually don't want to convert it into a string because |
|
| 36 | - * we'll lose all the FileSubmissionInterface data. So prefer to leave it alone. FileSubmissionInterface |
|
| 37 | - * can be cast to a string just fine so it's good as-is. |
|
| 38 | - * |
|
| 39 | - * @param string $normalized_value |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function unnormalize($normalized_value) |
|
| 43 | - { |
|
| 44 | - if ($normalized_value instanceof FileSubmissionInterface || is_null($normalized_value)) { |
|
| 45 | - // Leave it as the object, it can be treated like a string because it |
|
| 46 | - // overrides __toString() |
|
| 47 | - return $normalized_value; |
|
| 48 | - } else { |
|
| 49 | - return (string) $normalized_value; |
|
| 50 | - } |
|
| 51 | - } |
|
| 34 | + /** |
|
| 35 | + * This may be called prematurely on submitted data, so we actually don't want to convert it into a string because |
|
| 36 | + * we'll lose all the FileSubmissionInterface data. So prefer to leave it alone. FileSubmissionInterface |
|
| 37 | + * can be cast to a string just fine so it's good as-is. |
|
| 38 | + * |
|
| 39 | + * @param string $normalized_value |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function unnormalize($normalized_value) |
|
| 43 | + { |
|
| 44 | + if ($normalized_value instanceof FileSubmissionInterface || is_null($normalized_value)) { |
|
| 45 | + // Leave it as the object, it can be treated like a string because it |
|
| 46 | + // overrides __toString() |
|
| 47 | + return $normalized_value; |
|
| 48 | + } else { |
|
| 49 | + return (string) $normalized_value; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -13,747 +13,747 @@ |
||
| 13 | 13 | class EEM_Datetime extends EEM_Soft_Delete_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EEM_Datetime $_instance |
|
| 18 | - */ |
|
| 19 | - protected static $_instance; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * private constructor to prevent direct creation |
|
| 24 | - * |
|
| 25 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
| 26 | - * (and any incoming timezone data that gets saved). |
|
| 27 | - * Note this just sends the timezone info to the date time model field objects. |
|
| 28 | - * Default is NULL |
|
| 29 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 30 | - * @throws EE_Error |
|
| 31 | - * @throws InvalidArgumentException |
|
| 32 | - * @throws InvalidArgumentException |
|
| 33 | - */ |
|
| 34 | - protected function __construct($timezone) |
|
| 35 | - { |
|
| 36 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
| 37 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
| 38 | - $this->_tables = array( |
|
| 39 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
| 40 | - ); |
|
| 41 | - $this->_fields = array( |
|
| 42 | - 'Datetime' => array( |
|
| 43 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
| 44 | - 'DTT_ID', |
|
| 45 | - esc_html__('Datetime ID', 'event_espresso') |
|
| 46 | - ), |
|
| 47 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
| 48 | - 'EVT_ID', |
|
| 49 | - esc_html__('Event ID', 'event_espresso'), |
|
| 50 | - false, |
|
| 51 | - 0, |
|
| 52 | - 'Event' |
|
| 53 | - ), |
|
| 54 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
| 55 | - 'DTT_name', |
|
| 56 | - esc_html__('Datetime Name', 'event_espresso'), |
|
| 57 | - false, |
|
| 58 | - '' |
|
| 59 | - ), |
|
| 60 | - 'DTT_description' => new EE_Post_Content_Field( |
|
| 61 | - 'DTT_description', |
|
| 62 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
| 63 | - false, |
|
| 64 | - '' |
|
| 65 | - ), |
|
| 66 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
| 67 | - 'DTT_EVT_start', |
|
| 68 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
| 69 | - false, |
|
| 70 | - EE_Datetime_Field::now, |
|
| 71 | - $timezone |
|
| 72 | - ), |
|
| 73 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
| 74 | - 'DTT_EVT_end', |
|
| 75 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
| 76 | - false, |
|
| 77 | - EE_Datetime_Field::now, |
|
| 78 | - $timezone |
|
| 79 | - ), |
|
| 80 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
| 81 | - 'DTT_reg_limit', |
|
| 82 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
| 83 | - true, |
|
| 84 | - EE_INF |
|
| 85 | - ), |
|
| 86 | - 'DTT_sold' => new EE_Integer_Field( |
|
| 87 | - 'DTT_sold', |
|
| 88 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
| 89 | - true, |
|
| 90 | - 0 |
|
| 91 | - ), |
|
| 92 | - 'DTT_reserved' => new EE_Integer_Field( |
|
| 93 | - 'DTT_reserved', |
|
| 94 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
| 95 | - false, |
|
| 96 | - 0 |
|
| 97 | - ), |
|
| 98 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
| 99 | - 'DTT_is_primary', |
|
| 100 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
| 101 | - false, |
|
| 102 | - false |
|
| 103 | - ), |
|
| 104 | - 'DTT_order' => new EE_Integer_Field( |
|
| 105 | - 'DTT_order', |
|
| 106 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
| 107 | - false, |
|
| 108 | - 0 |
|
| 109 | - ), |
|
| 110 | - 'DTT_parent' => new EE_Integer_Field( |
|
| 111 | - 'DTT_parent', |
|
| 112 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
| 113 | - true, |
|
| 114 | - 0 |
|
| 115 | - ), |
|
| 116 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
| 117 | - 'DTT_deleted', |
|
| 118 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
| 119 | - false, |
|
| 120 | - false |
|
| 121 | - ), |
|
| 122 | - ), |
|
| 123 | - ); |
|
| 124 | - $this->_model_relations = array( |
|
| 125 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 126 | - 'Event' => new EE_Belongs_To_Relation(), |
|
| 127 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
| 128 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 129 | - ); |
|
| 130 | - $path_to_event_model = 'Event'; |
|
| 131 | - $this->model_chain_to_password = $path_to_event_model; |
|
| 132 | - $this->_model_chain_to_wp_user = $path_to_event_model; |
|
| 133 | - // this model is generally available for reading |
|
| 134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
| 135 | - $path_to_event_model |
|
| 136 | - ); |
|
| 137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 138 | - $path_to_event_model |
|
| 139 | - ); |
|
| 140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 141 | - $path_to_event_model |
|
| 142 | - ); |
|
| 143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 144 | - $path_to_event_model, |
|
| 145 | - EEM_Base::caps_edit |
|
| 146 | - ); |
|
| 147 | - parent::__construct($timezone); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * create new blank datetime |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
| 156 | - * @throws EE_Error |
|
| 157 | - * @throws InvalidArgumentException |
|
| 158 | - * @throws InvalidDataTypeException |
|
| 159 | - * @throws ReflectionException |
|
| 160 | - * @throws InvalidInterfaceException |
|
| 161 | - */ |
|
| 162 | - public function create_new_blank_datetime() |
|
| 163 | - { |
|
| 164 | - // makes sure timezone is always set. |
|
| 165 | - $timezone_string = $this->get_timezone(); |
|
| 166 | - /** |
|
| 167 | - * Filters the initial start date for the new datetime. |
|
| 168 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
| 169 | - * |
|
| 170 | - * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
| 171 | - * @return int unixtimestamp |
|
| 172 | - */ |
|
| 173 | - $start_date = apply_filters( |
|
| 174 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
| 175 | - $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
| 176 | - ); |
|
| 177 | - /** |
|
| 178 | - * Filters the initial end date for the new datetime. |
|
| 179 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
| 180 | - * |
|
| 181 | - * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
| 182 | - * @return int unixtimestamp |
|
| 183 | - */ |
|
| 184 | - $end_date = apply_filters( |
|
| 185 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
| 186 | - $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
| 187 | - ); |
|
| 188 | - $blank_datetime = EE_Datetime::new_instance( |
|
| 189 | - array( |
|
| 190 | - 'DTT_EVT_start' => $start_date, |
|
| 191 | - 'DTT_EVT_end' => $end_date, |
|
| 192 | - 'DTT_order' => 1, |
|
| 193 | - 'DTT_reg_limit' => EE_INF, |
|
| 194 | - ), |
|
| 195 | - $timezone_string |
|
| 196 | - ); |
|
| 197 | - /** |
|
| 198 | - * Filters the initial start time and format for the new EE_Datetime instance. |
|
| 199 | - * |
|
| 200 | - * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
| 201 | - * format. |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - $start_time = apply_filters( |
|
| 205 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
| 206 | - ['8am', 'ga'] |
|
| 207 | - ); |
|
| 208 | - /** |
|
| 209 | - * Filters the initial end time and format for the new EE_Datetime instance. |
|
| 210 | - * |
|
| 211 | - * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
| 212 | - * format |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - $end_time = apply_filters( |
|
| 216 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
| 217 | - ['5pm', 'ga'] |
|
| 218 | - ); |
|
| 219 | - $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
| 220 | - $blank_datetime->set_start_time( |
|
| 221 | - $this->convert_datetime_for_query( |
|
| 222 | - 'DTT_EVT_start', |
|
| 223 | - $start_time[0], |
|
| 224 | - $start_time[1], |
|
| 225 | - $timezone_string |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - $blank_datetime->set_end_time( |
|
| 229 | - $this->convert_datetime_for_query( |
|
| 230 | - 'DTT_EVT_end', |
|
| 231 | - $end_time[0], |
|
| 232 | - $end_time[1], |
|
| 233 | - $timezone_string |
|
| 234 | - ) |
|
| 235 | - ); |
|
| 236 | - return array($blank_datetime); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Validates whether the start_time and end_time are in the expected format. |
|
| 242 | - * @param array $start_time |
|
| 243 | - * @param array $end_time |
|
| 244 | - * @throws InvalidArgumentException |
|
| 245 | - * @throws InvalidDataTypeException |
|
| 246 | - */ |
|
| 247 | - private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
| 248 | - { |
|
| 249 | - if (! is_array($start_time)) { |
|
| 250 | - throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
| 251 | - } |
|
| 252 | - if (! is_array($end_time)) { |
|
| 253 | - throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
| 254 | - } |
|
| 255 | - if (count($start_time) !== 2) { |
|
| 256 | - throw new InvalidArgumentException( |
|
| 257 | - sprintf( |
|
| 258 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
| 259 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
| 260 | - '$start_time' |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - if (count($end_time) !== 2) { |
|
| 265 | - throw new InvalidArgumentException( |
|
| 266 | - sprintf( |
|
| 267 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
| 268 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
| 269 | - '$end_time' |
|
| 270 | - ) |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get event start date from db |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @param int $EVT_ID |
|
| 281 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
| 282 | - * @throws EE_Error |
|
| 283 | - */ |
|
| 284 | - public function get_all_event_dates($EVT_ID = 0) |
|
| 285 | - { |
|
| 286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
| 287 | - return $this->create_new_blank_datetime(); |
|
| 288 | - } |
|
| 289 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
| 290 | - if (empty($results)) { |
|
| 291 | - return $this->create_new_blank_datetime(); |
|
| 292 | - } |
|
| 293 | - return $results; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
| 299 | - * |
|
| 300 | - * @public |
|
| 301 | - * @param int $EVT_ID event id |
|
| 302 | - * @param boolean $include_expired |
|
| 303 | - * @param boolean $include_deleted |
|
| 304 | - * @param int $limit If included then limit the count of results by |
|
| 305 | - * the given number |
|
| 306 | - * @return EE_Datetime[] |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
| 310 | - $EVT_ID, |
|
| 311 | - $include_expired = true, |
|
| 312 | - $include_deleted = true, |
|
| 313 | - $limit = null |
|
| 314 | - ) { |
|
| 315 | - // sanitize EVT_ID |
|
| 316 | - $EVT_ID = absint($EVT_ID); |
|
| 317 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 318 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 319 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
| 320 | - $query_params = ! empty($limit) |
|
| 321 | - ? array( |
|
| 322 | - $where_params, |
|
| 323 | - 'limit' => $limit, |
|
| 324 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
| 325 | - 'default_where_conditions' => 'none', |
|
| 326 | - ) |
|
| 327 | - : array( |
|
| 328 | - $where_params, |
|
| 329 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
| 330 | - 'default_where_conditions' => 'none', |
|
| 331 | - ); |
|
| 332 | - if (! $include_expired) { |
|
| 333 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 334 | - } |
|
| 335 | - if ($include_deleted) { |
|
| 336 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 337 | - } |
|
| 338 | - /** @var EE_Datetime[] $result */ |
|
| 339 | - $result = $this->get_all($query_params); |
|
| 340 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 341 | - return $result; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
| 347 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
| 348 | - * and then the earlier datetimes are the most important. |
|
| 349 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
| 350 | - * |
|
| 351 | - * @param int $EVT_ID |
|
| 352 | - * @param int $limit |
|
| 353 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 354 | - * @throws EE_Error |
|
| 355 | - */ |
|
| 356 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
| 357 | - { |
|
| 358 | - return $this->get_all( |
|
| 359 | - array( |
|
| 360 | - array('Event.EVT_ID' => $EVT_ID), |
|
| 361 | - 'limit' => $limit, |
|
| 362 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 363 | - 'default_where_conditions' => 'none', |
|
| 364 | - ) |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param int $EVT_ID |
|
| 371 | - * @param boolean $include_expired |
|
| 372 | - * @param boolean $include_deleted |
|
| 373 | - * @return EE_Datetime |
|
| 374 | - * @throws EE_Error |
|
| 375 | - */ |
|
| 376 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
| 377 | - { |
|
| 378 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
| 379 | - $EVT_ID, |
|
| 380 | - $include_expired, |
|
| 381 | - $include_deleted, |
|
| 382 | - 1 |
|
| 383 | - ); |
|
| 384 | - if ($results) { |
|
| 385 | - return array_shift($results); |
|
| 386 | - } |
|
| 387 | - return null; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Gets the 'primary' datetime for an event. |
|
| 393 | - * |
|
| 394 | - * @param int $EVT_ID |
|
| 395 | - * @param bool $try_to_exclude_expired |
|
| 396 | - * @param bool $try_to_exclude_deleted |
|
| 397 | - * @return \EE_Datetime |
|
| 398 | - * @throws EE_Error |
|
| 399 | - */ |
|
| 400 | - public function get_primary_datetime_for_event( |
|
| 401 | - $EVT_ID, |
|
| 402 | - $try_to_exclude_expired = true, |
|
| 403 | - $try_to_exclude_deleted = true |
|
| 404 | - ) { |
|
| 405 | - if ($try_to_exclude_expired) { |
|
| 406 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
| 407 | - if ($non_expired) { |
|
| 408 | - return $non_expired; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - if ($try_to_exclude_deleted) { |
|
| 412 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
| 413 | - if ($expired_even) { |
|
| 414 | - return $expired_even; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
| 423 | - * only by start date |
|
| 424 | - * |
|
| 425 | - * @param int $EVT_ID |
|
| 426 | - * @param boolean $include_expired |
|
| 427 | - * @param boolean $include_deleted |
|
| 428 | - * @param int $limit |
|
| 429 | - * @return EE_Datetime[] |
|
| 430 | - * @throws EE_Error |
|
| 431 | - */ |
|
| 432 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
| 433 | - $EVT_ID, |
|
| 434 | - $include_expired = true, |
|
| 435 | - $include_deleted = true, |
|
| 436 | - $limit = null |
|
| 437 | - ) { |
|
| 438 | - // sanitize EVT_ID |
|
| 439 | - $EVT_ID = absint($EVT_ID); |
|
| 440 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 441 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 442 | - $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
| 443 | - if (! $include_expired) { |
|
| 444 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 445 | - } |
|
| 446 | - if ($include_deleted) { |
|
| 447 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 448 | - } |
|
| 449 | - if ($limit) { |
|
| 450 | - $query_params['limit'] = $limit; |
|
| 451 | - } |
|
| 452 | - /** @var EE_Datetime[] $result */ |
|
| 453 | - $result = $this->get_all($query_params); |
|
| 454 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 455 | - return $result; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
| 461 | - * only by start date |
|
| 462 | - * |
|
| 463 | - * @param int $TKT_ID |
|
| 464 | - * @param boolean $include_expired |
|
| 465 | - * @param boolean $include_deleted |
|
| 466 | - * @param int $limit |
|
| 467 | - * @return EE_Datetime[] |
|
| 468 | - * @throws EE_Error |
|
| 469 | - */ |
|
| 470 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
| 471 | - $TKT_ID, |
|
| 472 | - $include_expired = true, |
|
| 473 | - $include_deleted = true, |
|
| 474 | - $limit = null |
|
| 475 | - ) { |
|
| 476 | - // sanitize TKT_ID |
|
| 477 | - $TKT_ID = absint($TKT_ID); |
|
| 478 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 479 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 480 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
| 481 | - if (! $include_expired) { |
|
| 482 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 483 | - } |
|
| 484 | - if ($include_deleted) { |
|
| 485 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 486 | - } |
|
| 487 | - if ($limit) { |
|
| 488 | - $query_params['limit'] = $limit; |
|
| 489 | - } |
|
| 490 | - /** @var EE_Datetime[] $result */ |
|
| 491 | - $result = $this->get_all($query_params); |
|
| 492 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 493 | - return $result; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
| 499 | - * datetimes. |
|
| 500 | - * |
|
| 501 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
| 502 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
| 503 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
| 504 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
| 505 | - * that number |
|
| 506 | - * @return EE_Datetime[] |
|
| 507 | - * @throws EE_Error |
|
| 508 | - */ |
|
| 509 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 510 | - $TKT_ID, |
|
| 511 | - $include_expired = true, |
|
| 512 | - $include_deleted = true, |
|
| 513 | - $limit = null |
|
| 514 | - ) { |
|
| 515 | - // sanitize id. |
|
| 516 | - $TKT_ID = absint($TKT_ID); |
|
| 517 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 518 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 519 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
| 520 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
| 521 | - if (! $include_expired) { |
|
| 522 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 523 | - } |
|
| 524 | - if ($include_deleted) { |
|
| 525 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 526 | - } |
|
| 527 | - if ($limit) { |
|
| 528 | - $query_params['limit'] = $limit; |
|
| 529 | - } |
|
| 530 | - /** @var EE_Datetime[] $result */ |
|
| 531 | - $result = $this->get_all($query_params); |
|
| 532 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 533 | - return $result; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
| 539 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
| 540 | - * |
|
| 541 | - * @param int $EVT_ID |
|
| 542 | - * @return EE_Datetime |
|
| 543 | - * @throws EE_Error |
|
| 544 | - */ |
|
| 545 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
| 546 | - { |
|
| 547 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
| 548 | - if ($results) { |
|
| 549 | - return array_shift($results); |
|
| 550 | - } |
|
| 551 | - return null; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
| 557 | - * grouped by month and year. |
|
| 558 | - * |
|
| 559 | - * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
| 560 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
| 561 | - * Can be: |
|
| 562 | - * - '' = no filter |
|
| 563 | - * - upcoming = Published events with at least one upcoming datetime. |
|
| 564 | - * - expired = Events with all datetimes expired. |
|
| 565 | - * - active = Events that are published and have at least one datetime that |
|
| 566 | - * starts before now and ends after now. |
|
| 567 | - * - inactive = Events that are either not published. |
|
| 568 | - * @return EE_Base_Class[] |
|
| 569 | - * @throws EE_Error |
|
| 570 | - * @throws InvalidArgumentException |
|
| 571 | - * @throws InvalidArgumentException |
|
| 572 | - */ |
|
| 573 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
| 574 | - { |
|
| 575 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
| 576 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
| 577 | - switch ($evt_active_status) { |
|
| 578 | - case 'upcoming': |
|
| 579 | - $where_params['Event.status'] = 'publish'; |
|
| 580 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 581 | - if (isset($where_params['DTT_EVT_start'])) { |
|
| 582 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
| 583 | - } |
|
| 584 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
| 585 | - break; |
|
| 586 | - case 'expired': |
|
| 587 | - if (isset($where_params['Event.status'])) { |
|
| 588 | - unset($where_params['Event.status']); |
|
| 589 | - } |
|
| 590 | - // get events to exclude |
|
| 591 | - $exclude_query[0] = array_merge( |
|
| 592 | - $where_params, |
|
| 593 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
| 594 | - ); |
|
| 595 | - // first get all events that have datetimes where its not expired. |
|
| 596 | - $event_ids = $this->_get_all_wpdb_results( |
|
| 597 | - $exclude_query, |
|
| 598 | - OBJECT_K, |
|
| 599 | - 'Datetime.EVT_ID' |
|
| 600 | - ); |
|
| 601 | - $event_ids = array_keys($event_ids); |
|
| 602 | - if (isset($where_params['DTT_EVT_end'])) { |
|
| 603 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
| 604 | - } |
|
| 605 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
| 606 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
| 607 | - break; |
|
| 608 | - case 'active': |
|
| 609 | - $where_params['Event.status'] = 'publish'; |
|
| 610 | - if (isset($where_params['DTT_EVT_start'])) { |
|
| 611 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
| 612 | - } |
|
| 613 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 614 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
| 615 | - } |
|
| 616 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
| 617 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
| 618 | - break; |
|
| 619 | - case 'inactive': |
|
| 620 | - if (isset($where_params['Event.status'])) { |
|
| 621 | - unset($where_params['Event.status']); |
|
| 622 | - } |
|
| 623 | - if (isset($where_params['OR'])) { |
|
| 624 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 625 | - } |
|
| 626 | - if (isset($where_params['DTT_EVT_end'])) { |
|
| 627 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
| 628 | - unset($where_params['DTT_EVT_end']); |
|
| 629 | - } |
|
| 630 | - if (isset($where_params['DTT_EVT_start'])) { |
|
| 631 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
| 632 | - unset($where_params['DTT_EVT_start']); |
|
| 633 | - } |
|
| 634 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
| 635 | - break; |
|
| 636 | - } |
|
| 637 | - $query_params[0] = $where_params; |
|
| 638 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
| 639 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
| 640 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
| 641 | - $this->get_timezone(), |
|
| 642 | - 'DTT_EVT_start' |
|
| 643 | - ); |
|
| 644 | - $columns_to_select = array( |
|
| 645 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
| 646 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
| 647 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
| 648 | - ); |
|
| 649 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
| 655 | - * for the tickets for each datetime) |
|
| 656 | - * |
|
| 657 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
| 658 | - * @throws EE_Error |
|
| 659 | - */ |
|
| 660 | - public function update_sold($datetimes) |
|
| 661 | - { |
|
| 662 | - EE_Error::doing_it_wrong( |
|
| 663 | - __FUNCTION__, |
|
| 664 | - esc_html__( |
|
| 665 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
| 666 | - 'event_espresso' |
|
| 667 | - ), |
|
| 668 | - '4.9.32.rc.005' |
|
| 669 | - ); |
|
| 670 | - foreach ($datetimes as $datetime) { |
|
| 671 | - $datetime->update_sold(); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Gets the total number of tickets available at a particular datetime |
|
| 678 | - * (does NOT take into account the datetime's spaces available) |
|
| 679 | - * |
|
| 680 | - * @param int $DTT_ID |
|
| 681 | - * @param array $query_params |
|
| 682 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
| 683 | - * tickets attached to datetime then FALSE is returned. |
|
| 684 | - */ |
|
| 685 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
| 686 | - { |
|
| 687 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
| 688 | - if ($datetime instanceof EE_Datetime) { |
|
| 689 | - return $datetime->tickets_remaining($query_params); |
|
| 690 | - } |
|
| 691 | - return 0; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
| 697 | - * |
|
| 698 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
| 699 | - * stati you want counts for as values in the array. An empty array returns counts |
|
| 700 | - * for all valid stati. |
|
| 701 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
| 702 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
| 703 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
| 704 | - * @throws EE_Error |
|
| 705 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
| 706 | - * EE_Datetime::expired |
|
| 707 | - */ |
|
| 708 | - public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
| 709 | - { |
|
| 710 | - // only accept where conditions for this query. |
|
| 711 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 712 | - $status_query_args = array( |
|
| 713 | - EE_Datetime::active => array_merge( |
|
| 714 | - $_where, |
|
| 715 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
| 716 | - ), |
|
| 717 | - EE_Datetime::upcoming => array_merge( |
|
| 718 | - $_where, |
|
| 719 | - array('DTT_EVT_start' => array('>', time())) |
|
| 720 | - ), |
|
| 721 | - EE_Datetime::expired => array_merge( |
|
| 722 | - $_where, |
|
| 723 | - array('DTT_EVT_end' => array('<', time())) |
|
| 724 | - ), |
|
| 725 | - ); |
|
| 726 | - if (! empty($stati_to_include)) { |
|
| 727 | - foreach (array_keys($status_query_args) as $status) { |
|
| 728 | - if (! in_array($status, $stati_to_include, true)) { |
|
| 729 | - unset($status_query_args[ $status ]); |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - // loop through and query counts for each stati. |
|
| 734 | - $status_query_results = array(); |
|
| 735 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
| 736 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
| 737 | - array($status_where_conditions), |
|
| 738 | - 'DTT_ID', |
|
| 739 | - true |
|
| 740 | - ); |
|
| 741 | - } |
|
| 742 | - return $status_query_results; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
| 748 | - * |
|
| 749 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
| 750 | - * @param array $query_params |
|
| 751 | - * @return int |
|
| 752 | - * @throws EE_Error |
|
| 753 | - */ |
|
| 754 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
| 755 | - { |
|
| 756 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
| 757 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
| 758 | - } |
|
| 16 | + /** |
|
| 17 | + * @var EEM_Datetime $_instance |
|
| 18 | + */ |
|
| 19 | + protected static $_instance; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * private constructor to prevent direct creation |
|
| 24 | + * |
|
| 25 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
| 26 | + * (and any incoming timezone data that gets saved). |
|
| 27 | + * Note this just sends the timezone info to the date time model field objects. |
|
| 28 | + * Default is NULL |
|
| 29 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
| 30 | + * @throws EE_Error |
|
| 31 | + * @throws InvalidArgumentException |
|
| 32 | + * @throws InvalidArgumentException |
|
| 33 | + */ |
|
| 34 | + protected function __construct($timezone) |
|
| 35 | + { |
|
| 36 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
| 37 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
| 38 | + $this->_tables = array( |
|
| 39 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
| 40 | + ); |
|
| 41 | + $this->_fields = array( |
|
| 42 | + 'Datetime' => array( |
|
| 43 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
| 44 | + 'DTT_ID', |
|
| 45 | + esc_html__('Datetime ID', 'event_espresso') |
|
| 46 | + ), |
|
| 47 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
| 48 | + 'EVT_ID', |
|
| 49 | + esc_html__('Event ID', 'event_espresso'), |
|
| 50 | + false, |
|
| 51 | + 0, |
|
| 52 | + 'Event' |
|
| 53 | + ), |
|
| 54 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
| 55 | + 'DTT_name', |
|
| 56 | + esc_html__('Datetime Name', 'event_espresso'), |
|
| 57 | + false, |
|
| 58 | + '' |
|
| 59 | + ), |
|
| 60 | + 'DTT_description' => new EE_Post_Content_Field( |
|
| 61 | + 'DTT_description', |
|
| 62 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
| 63 | + false, |
|
| 64 | + '' |
|
| 65 | + ), |
|
| 66 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
| 67 | + 'DTT_EVT_start', |
|
| 68 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
| 69 | + false, |
|
| 70 | + EE_Datetime_Field::now, |
|
| 71 | + $timezone |
|
| 72 | + ), |
|
| 73 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
| 74 | + 'DTT_EVT_end', |
|
| 75 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
| 76 | + false, |
|
| 77 | + EE_Datetime_Field::now, |
|
| 78 | + $timezone |
|
| 79 | + ), |
|
| 80 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
| 81 | + 'DTT_reg_limit', |
|
| 82 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
| 83 | + true, |
|
| 84 | + EE_INF |
|
| 85 | + ), |
|
| 86 | + 'DTT_sold' => new EE_Integer_Field( |
|
| 87 | + 'DTT_sold', |
|
| 88 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
| 89 | + true, |
|
| 90 | + 0 |
|
| 91 | + ), |
|
| 92 | + 'DTT_reserved' => new EE_Integer_Field( |
|
| 93 | + 'DTT_reserved', |
|
| 94 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
| 95 | + false, |
|
| 96 | + 0 |
|
| 97 | + ), |
|
| 98 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
| 99 | + 'DTT_is_primary', |
|
| 100 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
| 101 | + false, |
|
| 102 | + false |
|
| 103 | + ), |
|
| 104 | + 'DTT_order' => new EE_Integer_Field( |
|
| 105 | + 'DTT_order', |
|
| 106 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
| 107 | + false, |
|
| 108 | + 0 |
|
| 109 | + ), |
|
| 110 | + 'DTT_parent' => new EE_Integer_Field( |
|
| 111 | + 'DTT_parent', |
|
| 112 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
| 113 | + true, |
|
| 114 | + 0 |
|
| 115 | + ), |
|
| 116 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
| 117 | + 'DTT_deleted', |
|
| 118 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
| 119 | + false, |
|
| 120 | + false |
|
| 121 | + ), |
|
| 122 | + ), |
|
| 123 | + ); |
|
| 124 | + $this->_model_relations = array( |
|
| 125 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
| 126 | + 'Event' => new EE_Belongs_To_Relation(), |
|
| 127 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
| 128 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
| 129 | + ); |
|
| 130 | + $path_to_event_model = 'Event'; |
|
| 131 | + $this->model_chain_to_password = $path_to_event_model; |
|
| 132 | + $this->_model_chain_to_wp_user = $path_to_event_model; |
|
| 133 | + // this model is generally available for reading |
|
| 134 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
| 135 | + $path_to_event_model |
|
| 136 | + ); |
|
| 137 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 138 | + $path_to_event_model |
|
| 139 | + ); |
|
| 140 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 141 | + $path_to_event_model |
|
| 142 | + ); |
|
| 143 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 144 | + $path_to_event_model, |
|
| 145 | + EEM_Base::caps_edit |
|
| 146 | + ); |
|
| 147 | + parent::__construct($timezone); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * create new blank datetime |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
| 156 | + * @throws EE_Error |
|
| 157 | + * @throws InvalidArgumentException |
|
| 158 | + * @throws InvalidDataTypeException |
|
| 159 | + * @throws ReflectionException |
|
| 160 | + * @throws InvalidInterfaceException |
|
| 161 | + */ |
|
| 162 | + public function create_new_blank_datetime() |
|
| 163 | + { |
|
| 164 | + // makes sure timezone is always set. |
|
| 165 | + $timezone_string = $this->get_timezone(); |
|
| 166 | + /** |
|
| 167 | + * Filters the initial start date for the new datetime. |
|
| 168 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
| 169 | + * |
|
| 170 | + * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
| 171 | + * @return int unixtimestamp |
|
| 172 | + */ |
|
| 173 | + $start_date = apply_filters( |
|
| 174 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
| 175 | + $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
| 176 | + ); |
|
| 177 | + /** |
|
| 178 | + * Filters the initial end date for the new datetime. |
|
| 179 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
| 180 | + * |
|
| 181 | + * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
| 182 | + * @return int unixtimestamp |
|
| 183 | + */ |
|
| 184 | + $end_date = apply_filters( |
|
| 185 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
| 186 | + $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
| 187 | + ); |
|
| 188 | + $blank_datetime = EE_Datetime::new_instance( |
|
| 189 | + array( |
|
| 190 | + 'DTT_EVT_start' => $start_date, |
|
| 191 | + 'DTT_EVT_end' => $end_date, |
|
| 192 | + 'DTT_order' => 1, |
|
| 193 | + 'DTT_reg_limit' => EE_INF, |
|
| 194 | + ), |
|
| 195 | + $timezone_string |
|
| 196 | + ); |
|
| 197 | + /** |
|
| 198 | + * Filters the initial start time and format for the new EE_Datetime instance. |
|
| 199 | + * |
|
| 200 | + * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
| 201 | + * format. |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + $start_time = apply_filters( |
|
| 205 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
| 206 | + ['8am', 'ga'] |
|
| 207 | + ); |
|
| 208 | + /** |
|
| 209 | + * Filters the initial end time and format for the new EE_Datetime instance. |
|
| 210 | + * |
|
| 211 | + * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
| 212 | + * format |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + $end_time = apply_filters( |
|
| 216 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
| 217 | + ['5pm', 'ga'] |
|
| 218 | + ); |
|
| 219 | + $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
| 220 | + $blank_datetime->set_start_time( |
|
| 221 | + $this->convert_datetime_for_query( |
|
| 222 | + 'DTT_EVT_start', |
|
| 223 | + $start_time[0], |
|
| 224 | + $start_time[1], |
|
| 225 | + $timezone_string |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + $blank_datetime->set_end_time( |
|
| 229 | + $this->convert_datetime_for_query( |
|
| 230 | + 'DTT_EVT_end', |
|
| 231 | + $end_time[0], |
|
| 232 | + $end_time[1], |
|
| 233 | + $timezone_string |
|
| 234 | + ) |
|
| 235 | + ); |
|
| 236 | + return array($blank_datetime); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Validates whether the start_time and end_time are in the expected format. |
|
| 242 | + * @param array $start_time |
|
| 243 | + * @param array $end_time |
|
| 244 | + * @throws InvalidArgumentException |
|
| 245 | + * @throws InvalidDataTypeException |
|
| 246 | + */ |
|
| 247 | + private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
| 248 | + { |
|
| 249 | + if (! is_array($start_time)) { |
|
| 250 | + throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
| 251 | + } |
|
| 252 | + if (! is_array($end_time)) { |
|
| 253 | + throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
| 254 | + } |
|
| 255 | + if (count($start_time) !== 2) { |
|
| 256 | + throw new InvalidArgumentException( |
|
| 257 | + sprintf( |
|
| 258 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
| 259 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
| 260 | + '$start_time' |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + if (count($end_time) !== 2) { |
|
| 265 | + throw new InvalidArgumentException( |
|
| 266 | + sprintf( |
|
| 267 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
| 268 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
| 269 | + '$end_time' |
|
| 270 | + ) |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get event start date from db |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @param int $EVT_ID |
|
| 281 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
| 282 | + * @throws EE_Error |
|
| 283 | + */ |
|
| 284 | + public function get_all_event_dates($EVT_ID = 0) |
|
| 285 | + { |
|
| 286 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
| 287 | + return $this->create_new_blank_datetime(); |
|
| 288 | + } |
|
| 289 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
| 290 | + if (empty($results)) { |
|
| 291 | + return $this->create_new_blank_datetime(); |
|
| 292 | + } |
|
| 293 | + return $results; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
| 299 | + * |
|
| 300 | + * @public |
|
| 301 | + * @param int $EVT_ID event id |
|
| 302 | + * @param boolean $include_expired |
|
| 303 | + * @param boolean $include_deleted |
|
| 304 | + * @param int $limit If included then limit the count of results by |
|
| 305 | + * the given number |
|
| 306 | + * @return EE_Datetime[] |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
| 310 | + $EVT_ID, |
|
| 311 | + $include_expired = true, |
|
| 312 | + $include_deleted = true, |
|
| 313 | + $limit = null |
|
| 314 | + ) { |
|
| 315 | + // sanitize EVT_ID |
|
| 316 | + $EVT_ID = absint($EVT_ID); |
|
| 317 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 318 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 319 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
| 320 | + $query_params = ! empty($limit) |
|
| 321 | + ? array( |
|
| 322 | + $where_params, |
|
| 323 | + 'limit' => $limit, |
|
| 324 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
| 325 | + 'default_where_conditions' => 'none', |
|
| 326 | + ) |
|
| 327 | + : array( |
|
| 328 | + $where_params, |
|
| 329 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
| 330 | + 'default_where_conditions' => 'none', |
|
| 331 | + ); |
|
| 332 | + if (! $include_expired) { |
|
| 333 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 334 | + } |
|
| 335 | + if ($include_deleted) { |
|
| 336 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 337 | + } |
|
| 338 | + /** @var EE_Datetime[] $result */ |
|
| 339 | + $result = $this->get_all($query_params); |
|
| 340 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 341 | + return $result; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
| 347 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
| 348 | + * and then the earlier datetimes are the most important. |
|
| 349 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
| 350 | + * |
|
| 351 | + * @param int $EVT_ID |
|
| 352 | + * @param int $limit |
|
| 353 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 354 | + * @throws EE_Error |
|
| 355 | + */ |
|
| 356 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
| 357 | + { |
|
| 358 | + return $this->get_all( |
|
| 359 | + array( |
|
| 360 | + array('Event.EVT_ID' => $EVT_ID), |
|
| 361 | + 'limit' => $limit, |
|
| 362 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 363 | + 'default_where_conditions' => 'none', |
|
| 364 | + ) |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param int $EVT_ID |
|
| 371 | + * @param boolean $include_expired |
|
| 372 | + * @param boolean $include_deleted |
|
| 373 | + * @return EE_Datetime |
|
| 374 | + * @throws EE_Error |
|
| 375 | + */ |
|
| 376 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
| 377 | + { |
|
| 378 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
| 379 | + $EVT_ID, |
|
| 380 | + $include_expired, |
|
| 381 | + $include_deleted, |
|
| 382 | + 1 |
|
| 383 | + ); |
|
| 384 | + if ($results) { |
|
| 385 | + return array_shift($results); |
|
| 386 | + } |
|
| 387 | + return null; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Gets the 'primary' datetime for an event. |
|
| 393 | + * |
|
| 394 | + * @param int $EVT_ID |
|
| 395 | + * @param bool $try_to_exclude_expired |
|
| 396 | + * @param bool $try_to_exclude_deleted |
|
| 397 | + * @return \EE_Datetime |
|
| 398 | + * @throws EE_Error |
|
| 399 | + */ |
|
| 400 | + public function get_primary_datetime_for_event( |
|
| 401 | + $EVT_ID, |
|
| 402 | + $try_to_exclude_expired = true, |
|
| 403 | + $try_to_exclude_deleted = true |
|
| 404 | + ) { |
|
| 405 | + if ($try_to_exclude_expired) { |
|
| 406 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
| 407 | + if ($non_expired) { |
|
| 408 | + return $non_expired; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + if ($try_to_exclude_deleted) { |
|
| 412 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
| 413 | + if ($expired_even) { |
|
| 414 | + return $expired_even; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
| 423 | + * only by start date |
|
| 424 | + * |
|
| 425 | + * @param int $EVT_ID |
|
| 426 | + * @param boolean $include_expired |
|
| 427 | + * @param boolean $include_deleted |
|
| 428 | + * @param int $limit |
|
| 429 | + * @return EE_Datetime[] |
|
| 430 | + * @throws EE_Error |
|
| 431 | + */ |
|
| 432 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
| 433 | + $EVT_ID, |
|
| 434 | + $include_expired = true, |
|
| 435 | + $include_deleted = true, |
|
| 436 | + $limit = null |
|
| 437 | + ) { |
|
| 438 | + // sanitize EVT_ID |
|
| 439 | + $EVT_ID = absint($EVT_ID); |
|
| 440 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 441 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 442 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
| 443 | + if (! $include_expired) { |
|
| 444 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 445 | + } |
|
| 446 | + if ($include_deleted) { |
|
| 447 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 448 | + } |
|
| 449 | + if ($limit) { |
|
| 450 | + $query_params['limit'] = $limit; |
|
| 451 | + } |
|
| 452 | + /** @var EE_Datetime[] $result */ |
|
| 453 | + $result = $this->get_all($query_params); |
|
| 454 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 455 | + return $result; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
| 461 | + * only by start date |
|
| 462 | + * |
|
| 463 | + * @param int $TKT_ID |
|
| 464 | + * @param boolean $include_expired |
|
| 465 | + * @param boolean $include_deleted |
|
| 466 | + * @param int $limit |
|
| 467 | + * @return EE_Datetime[] |
|
| 468 | + * @throws EE_Error |
|
| 469 | + */ |
|
| 470 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
| 471 | + $TKT_ID, |
|
| 472 | + $include_expired = true, |
|
| 473 | + $include_deleted = true, |
|
| 474 | + $limit = null |
|
| 475 | + ) { |
|
| 476 | + // sanitize TKT_ID |
|
| 477 | + $TKT_ID = absint($TKT_ID); |
|
| 478 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 479 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 480 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
| 481 | + if (! $include_expired) { |
|
| 482 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 483 | + } |
|
| 484 | + if ($include_deleted) { |
|
| 485 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 486 | + } |
|
| 487 | + if ($limit) { |
|
| 488 | + $query_params['limit'] = $limit; |
|
| 489 | + } |
|
| 490 | + /** @var EE_Datetime[] $result */ |
|
| 491 | + $result = $this->get_all($query_params); |
|
| 492 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 493 | + return $result; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
| 499 | + * datetimes. |
|
| 500 | + * |
|
| 501 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
| 502 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
| 503 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
| 504 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
| 505 | + * that number |
|
| 506 | + * @return EE_Datetime[] |
|
| 507 | + * @throws EE_Error |
|
| 508 | + */ |
|
| 509 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 510 | + $TKT_ID, |
|
| 511 | + $include_expired = true, |
|
| 512 | + $include_deleted = true, |
|
| 513 | + $limit = null |
|
| 514 | + ) { |
|
| 515 | + // sanitize id. |
|
| 516 | + $TKT_ID = absint($TKT_ID); |
|
| 517 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 518 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
| 519 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
| 520 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
| 521 | + if (! $include_expired) { |
|
| 522 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
| 523 | + } |
|
| 524 | + if ($include_deleted) { |
|
| 525 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
| 526 | + } |
|
| 527 | + if ($limit) { |
|
| 528 | + $query_params['limit'] = $limit; |
|
| 529 | + } |
|
| 530 | + /** @var EE_Datetime[] $result */ |
|
| 531 | + $result = $this->get_all($query_params); |
|
| 532 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
| 533 | + return $result; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
| 539 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
| 540 | + * |
|
| 541 | + * @param int $EVT_ID |
|
| 542 | + * @return EE_Datetime |
|
| 543 | + * @throws EE_Error |
|
| 544 | + */ |
|
| 545 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
| 546 | + { |
|
| 547 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
| 548 | + if ($results) { |
|
| 549 | + return array_shift($results); |
|
| 550 | + } |
|
| 551 | + return null; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
| 557 | + * grouped by month and year. |
|
| 558 | + * |
|
| 559 | + * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
| 560 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
| 561 | + * Can be: |
|
| 562 | + * - '' = no filter |
|
| 563 | + * - upcoming = Published events with at least one upcoming datetime. |
|
| 564 | + * - expired = Events with all datetimes expired. |
|
| 565 | + * - active = Events that are published and have at least one datetime that |
|
| 566 | + * starts before now and ends after now. |
|
| 567 | + * - inactive = Events that are either not published. |
|
| 568 | + * @return EE_Base_Class[] |
|
| 569 | + * @throws EE_Error |
|
| 570 | + * @throws InvalidArgumentException |
|
| 571 | + * @throws InvalidArgumentException |
|
| 572 | + */ |
|
| 573 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
| 574 | + { |
|
| 575 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
| 576 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
| 577 | + switch ($evt_active_status) { |
|
| 578 | + case 'upcoming': |
|
| 579 | + $where_params['Event.status'] = 'publish'; |
|
| 580 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 581 | + if (isset($where_params['DTT_EVT_start'])) { |
|
| 582 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
| 583 | + } |
|
| 584 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
| 585 | + break; |
|
| 586 | + case 'expired': |
|
| 587 | + if (isset($where_params['Event.status'])) { |
|
| 588 | + unset($where_params['Event.status']); |
|
| 589 | + } |
|
| 590 | + // get events to exclude |
|
| 591 | + $exclude_query[0] = array_merge( |
|
| 592 | + $where_params, |
|
| 593 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
| 594 | + ); |
|
| 595 | + // first get all events that have datetimes where its not expired. |
|
| 596 | + $event_ids = $this->_get_all_wpdb_results( |
|
| 597 | + $exclude_query, |
|
| 598 | + OBJECT_K, |
|
| 599 | + 'Datetime.EVT_ID' |
|
| 600 | + ); |
|
| 601 | + $event_ids = array_keys($event_ids); |
|
| 602 | + if (isset($where_params['DTT_EVT_end'])) { |
|
| 603 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
| 604 | + } |
|
| 605 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
| 606 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
| 607 | + break; |
|
| 608 | + case 'active': |
|
| 609 | + $where_params['Event.status'] = 'publish'; |
|
| 610 | + if (isset($where_params['DTT_EVT_start'])) { |
|
| 611 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
| 612 | + } |
|
| 613 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 614 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
| 615 | + } |
|
| 616 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
| 617 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
| 618 | + break; |
|
| 619 | + case 'inactive': |
|
| 620 | + if (isset($where_params['Event.status'])) { |
|
| 621 | + unset($where_params['Event.status']); |
|
| 622 | + } |
|
| 623 | + if (isset($where_params['OR'])) { |
|
| 624 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 625 | + } |
|
| 626 | + if (isset($where_params['DTT_EVT_end'])) { |
|
| 627 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
| 628 | + unset($where_params['DTT_EVT_end']); |
|
| 629 | + } |
|
| 630 | + if (isset($where_params['DTT_EVT_start'])) { |
|
| 631 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
| 632 | + unset($where_params['DTT_EVT_start']); |
|
| 633 | + } |
|
| 634 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
| 635 | + break; |
|
| 636 | + } |
|
| 637 | + $query_params[0] = $where_params; |
|
| 638 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
| 639 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
| 640 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
| 641 | + $this->get_timezone(), |
|
| 642 | + 'DTT_EVT_start' |
|
| 643 | + ); |
|
| 644 | + $columns_to_select = array( |
|
| 645 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
| 646 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
| 647 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
| 648 | + ); |
|
| 649 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
| 655 | + * for the tickets for each datetime) |
|
| 656 | + * |
|
| 657 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
| 658 | + * @throws EE_Error |
|
| 659 | + */ |
|
| 660 | + public function update_sold($datetimes) |
|
| 661 | + { |
|
| 662 | + EE_Error::doing_it_wrong( |
|
| 663 | + __FUNCTION__, |
|
| 664 | + esc_html__( |
|
| 665 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
| 666 | + 'event_espresso' |
|
| 667 | + ), |
|
| 668 | + '4.9.32.rc.005' |
|
| 669 | + ); |
|
| 670 | + foreach ($datetimes as $datetime) { |
|
| 671 | + $datetime->update_sold(); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Gets the total number of tickets available at a particular datetime |
|
| 678 | + * (does NOT take into account the datetime's spaces available) |
|
| 679 | + * |
|
| 680 | + * @param int $DTT_ID |
|
| 681 | + * @param array $query_params |
|
| 682 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
| 683 | + * tickets attached to datetime then FALSE is returned. |
|
| 684 | + */ |
|
| 685 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
| 686 | + { |
|
| 687 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
| 688 | + if ($datetime instanceof EE_Datetime) { |
|
| 689 | + return $datetime->tickets_remaining($query_params); |
|
| 690 | + } |
|
| 691 | + return 0; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
| 697 | + * |
|
| 698 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
| 699 | + * stati you want counts for as values in the array. An empty array returns counts |
|
| 700 | + * for all valid stati. |
|
| 701 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
| 702 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
| 703 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
| 704 | + * @throws EE_Error |
|
| 705 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
| 706 | + * EE_Datetime::expired |
|
| 707 | + */ |
|
| 708 | + public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
| 709 | + { |
|
| 710 | + // only accept where conditions for this query. |
|
| 711 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 712 | + $status_query_args = array( |
|
| 713 | + EE_Datetime::active => array_merge( |
|
| 714 | + $_where, |
|
| 715 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
| 716 | + ), |
|
| 717 | + EE_Datetime::upcoming => array_merge( |
|
| 718 | + $_where, |
|
| 719 | + array('DTT_EVT_start' => array('>', time())) |
|
| 720 | + ), |
|
| 721 | + EE_Datetime::expired => array_merge( |
|
| 722 | + $_where, |
|
| 723 | + array('DTT_EVT_end' => array('<', time())) |
|
| 724 | + ), |
|
| 725 | + ); |
|
| 726 | + if (! empty($stati_to_include)) { |
|
| 727 | + foreach (array_keys($status_query_args) as $status) { |
|
| 728 | + if (! in_array($status, $stati_to_include, true)) { |
|
| 729 | + unset($status_query_args[ $status ]); |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + // loop through and query counts for each stati. |
|
| 734 | + $status_query_results = array(); |
|
| 735 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
| 736 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
| 737 | + array($status_where_conditions), |
|
| 738 | + 'DTT_ID', |
|
| 739 | + true |
|
| 740 | + ); |
|
| 741 | + } |
|
| 742 | + return $status_query_results; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
| 748 | + * |
|
| 749 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
| 750 | + * @param array $query_params |
|
| 751 | + * @return int |
|
| 752 | + * @throws EE_Error |
|
| 753 | + */ |
|
| 754 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
| 755 | + { |
|
| 756 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
| 757 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
| 758 | + } |
|
| 759 | 759 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | ), |
| 122 | 122 | ), |
| 123 | 123 | ); |
| 124 | - $this->_model_relations = array( |
|
| 124 | + $this->_model_relations = array( |
|
| 125 | 125 | 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
| 126 | 126 | 'Event' => new EE_Belongs_To_Relation(), |
| 127 | 127 | 'Checkin' => new EE_Has_Many_Relation(), |
@@ -131,16 +131,16 @@ discard block |
||
| 131 | 131 | $this->model_chain_to_password = $path_to_event_model; |
| 132 | 132 | $this->_model_chain_to_wp_user = $path_to_event_model; |
| 133 | 133 | // this model is generally available for reading |
| 134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
| 134 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
| 135 | 135 | $path_to_event_model |
| 136 | 136 | ); |
| 137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 137 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 138 | 138 | $path_to_event_model |
| 139 | 139 | ); |
| 140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 140 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 141 | 141 | $path_to_event_model |
| 142 | 142 | ); |
| 143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 143 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
| 144 | 144 | $path_to_event_model, |
| 145 | 145 | EEM_Base::caps_edit |
| 146 | 146 | ); |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
| 248 | 248 | { |
| 249 | - if (! is_array($start_time)) { |
|
| 249 | + if ( ! is_array($start_time)) { |
|
| 250 | 250 | throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
| 251 | 251 | } |
| 252 | - if (! is_array($end_time)) { |
|
| 252 | + if ( ! is_array($end_time)) { |
|
| 253 | 253 | throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
| 254 | 254 | } |
| 255 | 255 | if (count($start_time) !== 2) { |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | public function get_all_event_dates($EVT_ID = 0) |
| 285 | 285 | { |
| 286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
| 286 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
| 287 | 287 | return $this->create_new_blank_datetime(); |
| 288 | 288 | } |
| 289 | 289 | $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | 'order_by' => array('DTT_order' => 'ASC'), |
| 330 | 330 | 'default_where_conditions' => 'none', |
| 331 | 331 | ); |
| 332 | - if (! $include_expired) { |
|
| 332 | + if ( ! $include_expired) { |
|
| 333 | 333 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
| 334 | 334 | } |
| 335 | 335 | if ($include_deleted) { |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
| 441 | 441 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
| 442 | 442 | $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
| 443 | - if (! $include_expired) { |
|
| 443 | + if ( ! $include_expired) { |
|
| 444 | 444 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
| 445 | 445 | } |
| 446 | 446 | if ($include_deleted) { |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
| 479 | 479 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
| 480 | 480 | $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
| 481 | - if (! $include_expired) { |
|
| 481 | + if ( ! $include_expired) { |
|
| 482 | 482 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
| 483 | 483 | } |
| 484 | 484 | if ($include_deleted) { |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
| 519 | 519 | $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
| 520 | 520 | $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
| 521 | - if (! $include_expired) { |
|
| 521 | + if ( ! $include_expired) { |
|
| 522 | 522 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
| 523 | 523 | } |
| 524 | 524 | if ($include_deleted) { |
@@ -641,10 +641,10 @@ discard block |
||
| 641 | 641 | $this->get_timezone(), |
| 642 | 642 | 'DTT_EVT_start' |
| 643 | 643 | ); |
| 644 | - $columns_to_select = array( |
|
| 645 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
| 646 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
| 647 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
| 644 | + $columns_to_select = array( |
|
| 645 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
| 646 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
| 647 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'), |
|
| 648 | 648 | ); |
| 649 | 649 | return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
| 650 | 650 | } |
@@ -723,17 +723,17 @@ discard block |
||
| 723 | 723 | array('DTT_EVT_end' => array('<', time())) |
| 724 | 724 | ), |
| 725 | 725 | ); |
| 726 | - if (! empty($stati_to_include)) { |
|
| 726 | + if ( ! empty($stati_to_include)) { |
|
| 727 | 727 | foreach (array_keys($status_query_args) as $status) { |
| 728 | - if (! in_array($status, $stati_to_include, true)) { |
|
| 729 | - unset($status_query_args[ $status ]); |
|
| 728 | + if ( ! in_array($status, $stati_to_include, true)) { |
|
| 729 | + unset($status_query_args[$status]); |
|
| 730 | 730 | } |
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | // loop through and query counts for each stati. |
| 734 | 734 | $status_query_results = array(); |
| 735 | 735 | foreach ($status_query_args as $status => $status_where_conditions) { |
| 736 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
| 736 | + $status_query_results[$status] = EEM_Datetime::count( |
|
| 737 | 737 | array($status_where_conditions), |
| 738 | 738 | 'DTT_ID', |
| 739 | 739 | true |
@@ -754,6 +754,6 @@ discard block |
||
| 754 | 754 | public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
| 755 | 755 | { |
| 756 | 756 | $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
| 757 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
| 757 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
| 758 | 758 | } |
| 759 | 759 | } |
@@ -53,10 +53,6 @@ discard block |
||
| 53 | 53 | ENGINE=InnoDB |
| 54 | 54 | AUTO_INCREMENT=3 |
| 55 | 55 | ; |
| 56 | - |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | 56 | * 4.1 Attendee tables and fields: |
| 61 | 57 | * $this->_tables = array( |
| 62 | 58 | 'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'), |
@@ -186,637 +182,637 @@ discard block |
||
| 186 | 182 | */ |
| 187 | 183 | class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table |
| 188 | 184 | { |
| 189 | - private $_new_attendee_cpt_table; |
|
| 190 | - private $_new_attendee_meta_table; |
|
| 191 | - private $_new_reg_table; |
|
| 192 | - private $_new_transaction_table; |
|
| 193 | - private $_new_payment_table; |
|
| 194 | - private $_new_line_table; |
|
| 195 | - private $_old_mer_table; |
|
| 196 | - private $_new_ticket_table; |
|
| 197 | - private $_new_ticket_datetime_table; |
|
| 198 | - private $_new_datetime_table; |
|
| 199 | - private $_new_datetime_ticket_table; |
|
| 200 | - private $_new_price_table; |
|
| 201 | - private $_new_ticket_price_table; |
|
| 202 | - /** |
|
| 203 | - * Rememebrs whether or not the mer table exists |
|
| 204 | - * @var boolean |
|
| 205 | - */ |
|
| 206 | - private $_mer_tables_exist = null; |
|
| 207 | - public function __construct() |
|
| 208 | - { |
|
| 209 | - global $wpdb; |
|
| 210 | - $this->_pretty_name = __("Attendees", "event_espresso"); |
|
| 211 | - $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 212 | - // Only select the event status column from the event table. |
|
| 213 | - $this->select_expression = 'att.*, e.event_status'; |
|
| 214 | - // Only select attendees for events that aren't deleted. |
|
| 215 | - $this->_extra_where_sql = 'AS att |
|
| 185 | + private $_new_attendee_cpt_table; |
|
| 186 | + private $_new_attendee_meta_table; |
|
| 187 | + private $_new_reg_table; |
|
| 188 | + private $_new_transaction_table; |
|
| 189 | + private $_new_payment_table; |
|
| 190 | + private $_new_line_table; |
|
| 191 | + private $_old_mer_table; |
|
| 192 | + private $_new_ticket_table; |
|
| 193 | + private $_new_ticket_datetime_table; |
|
| 194 | + private $_new_datetime_table; |
|
| 195 | + private $_new_datetime_ticket_table; |
|
| 196 | + private $_new_price_table; |
|
| 197 | + private $_new_ticket_price_table; |
|
| 198 | + /** |
|
| 199 | + * Rememebrs whether or not the mer table exists |
|
| 200 | + * @var boolean |
|
| 201 | + */ |
|
| 202 | + private $_mer_tables_exist = null; |
|
| 203 | + public function __construct() |
|
| 204 | + { |
|
| 205 | + global $wpdb; |
|
| 206 | + $this->_pretty_name = __("Attendees", "event_espresso"); |
|
| 207 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
| 208 | + // Only select the event status column from the event table. |
|
| 209 | + $this->select_expression = 'att.*, e.event_status'; |
|
| 210 | + // Only select attendees for events that aren't deleted. |
|
| 211 | + $this->_extra_where_sql = 'AS att |
|
| 216 | 212 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
| 217 | 213 | WHERE e.event_status!="D"'; |
| 218 | - $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
| 219 | - $this->_new_attendee_cpt_table = $wpdb->posts; |
|
| 220 | - $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
| 221 | - $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 222 | - $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 223 | - $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
| 224 | - $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 225 | - $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 226 | - $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 227 | - $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 228 | - $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 229 | - $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 230 | - $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 231 | - parent::__construct(); |
|
| 232 | - } |
|
| 214 | + $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
| 215 | + $this->_new_attendee_cpt_table = $wpdb->posts; |
|
| 216 | + $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
| 217 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 218 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
| 219 | + $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
| 220 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
| 221 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 222 | + $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 223 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 224 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
| 225 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
| 226 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 227 | + parent::__construct(); |
|
| 228 | + } |
|
| 233 | 229 | |
| 234 | - protected function _migrate_old_row($old_row) |
|
| 235 | - { |
|
| 236 | - // first check if there's already a new attendee with similar characteristics |
|
| 237 | - $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
| 238 | - if (! $new_att_id) { |
|
| 239 | - $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
| 240 | - if (! $new_att_id) { |
|
| 241 | - // if we couldnt even make an attendee, abandon all hope |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
| 245 | - if ($new_att_meta_id) { |
|
| 246 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
| 230 | + protected function _migrate_old_row($old_row) |
|
| 231 | + { |
|
| 232 | + // first check if there's already a new attendee with similar characteristics |
|
| 233 | + $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
| 234 | + if (! $new_att_id) { |
|
| 235 | + $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
| 236 | + if (! $new_att_id) { |
|
| 237 | + // if we couldnt even make an attendee, abandon all hope |
|
| 238 | + return false; |
|
| 239 | + } |
|
| 240 | + $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
| 241 | + if ($new_att_meta_id) { |
|
| 242 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
| 250 | 246 | |
| 251 | - $txn_id = $this->_insert_new_transaction($old_row); |
|
| 252 | - if (! $txn_id) { |
|
| 253 | - // if we couldnt make the transaction, also abandon all hope |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
| 257 | - $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
| 258 | - if ($pay_id) { |
|
| 259 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
| 260 | - } |
|
| 247 | + $txn_id = $this->_insert_new_transaction($old_row); |
|
| 248 | + if (! $txn_id) { |
|
| 249 | + // if we couldnt make the transaction, also abandon all hope |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
| 253 | + $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
| 254 | + if ($pay_id) { |
|
| 255 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
| 256 | + } |
|
| 261 | 257 | |
| 262 | 258 | |
| 263 | - // even if there was no payment, we can go ahead with adding the reg |
|
| 264 | - $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
| 265 | - if ($new_regs) { |
|
| 266 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - /** |
|
| 270 | - * Checks if there's already an attendee CPT in the db that has the same |
|
| 271 | - * first and last name, and email. If so, returns its ID as an int. |
|
| 272 | - * @global type $wpdb |
|
| 273 | - * @param array $old_attendee |
|
| 274 | - * @return int |
|
| 275 | - */ |
|
| 276 | - private function _find_attendee_cpt_matching($old_attendee) |
|
| 277 | - { |
|
| 278 | - global $wpdb; |
|
| 279 | - $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
| 280 | - return intval($existing_attendee_id); |
|
| 281 | - } |
|
| 282 | - private function _insert_new_attendee_cpt($old_attendee) |
|
| 283 | - { |
|
| 284 | - global $wpdb; |
|
| 285 | - $cols_n_values = array( |
|
| 286 | - 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 287 | - 'post_content'=>'',// ATT_bio |
|
| 288 | - 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 289 | - 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 290 | - 'post_excerpt'=>'',// ATT_short_bio |
|
| 291 | - 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 292 | - 'post_author'=>0,// ATT_author |
|
| 293 | - 'post_parent'=>0,// ATT_parent |
|
| 294 | - 'post_type'=>'espresso_attendees',// post_type |
|
| 295 | - 'post_status'=>'publish'// status |
|
| 296 | - ); |
|
| 297 | - $datatypes = array( |
|
| 298 | - '%s',// ATT_full_name |
|
| 299 | - '%s',// ATT_bio |
|
| 300 | - '%s',// ATT_slug |
|
| 301 | - '%s',// ATT_created |
|
| 302 | - '%s',// ATT_short_bio |
|
| 303 | - '%s',// ATT_modified |
|
| 304 | - '%d',// ATT_author |
|
| 305 | - '%d',// ATT_parent |
|
| 306 | - '%s',// post_type |
|
| 307 | - '%s',// status |
|
| 308 | - ); |
|
| 309 | - $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
| 310 | - if (! $success) { |
|
| 311 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
| 312 | - return 0; |
|
| 313 | - } |
|
| 314 | - $new_id = $wpdb->insert_id; |
|
| 315 | - return $new_id; |
|
| 316 | - } |
|
| 259 | + // even if there was no payment, we can go ahead with adding the reg |
|
| 260 | + $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
| 261 | + if ($new_regs) { |
|
| 262 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + /** |
|
| 266 | + * Checks if there's already an attendee CPT in the db that has the same |
|
| 267 | + * first and last name, and email. If so, returns its ID as an int. |
|
| 268 | + * @global type $wpdb |
|
| 269 | + * @param array $old_attendee |
|
| 270 | + * @return int |
|
| 271 | + */ |
|
| 272 | + private function _find_attendee_cpt_matching($old_attendee) |
|
| 273 | + { |
|
| 274 | + global $wpdb; |
|
| 275 | + $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
| 276 | + return intval($existing_attendee_id); |
|
| 277 | + } |
|
| 278 | + private function _insert_new_attendee_cpt($old_attendee) |
|
| 279 | + { |
|
| 280 | + global $wpdb; |
|
| 281 | + $cols_n_values = array( |
|
| 282 | + 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 283 | + 'post_content'=>'',// ATT_bio |
|
| 284 | + 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 285 | + 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 286 | + 'post_excerpt'=>'',// ATT_short_bio |
|
| 287 | + 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 288 | + 'post_author'=>0,// ATT_author |
|
| 289 | + 'post_parent'=>0,// ATT_parent |
|
| 290 | + 'post_type'=>'espresso_attendees',// post_type |
|
| 291 | + 'post_status'=>'publish'// status |
|
| 292 | + ); |
|
| 293 | + $datatypes = array( |
|
| 294 | + '%s',// ATT_full_name |
|
| 295 | + '%s',// ATT_bio |
|
| 296 | + '%s',// ATT_slug |
|
| 297 | + '%s',// ATT_created |
|
| 298 | + '%s',// ATT_short_bio |
|
| 299 | + '%s',// ATT_modified |
|
| 300 | + '%d',// ATT_author |
|
| 301 | + '%d',// ATT_parent |
|
| 302 | + '%s',// post_type |
|
| 303 | + '%s',// status |
|
| 304 | + ); |
|
| 305 | + $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
| 306 | + if (! $success) { |
|
| 307 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
| 308 | + return 0; |
|
| 309 | + } |
|
| 310 | + $new_id = $wpdb->insert_id; |
|
| 311 | + return $new_id; |
|
| 312 | + } |
|
| 317 | 313 | |
| 318 | - private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
| 319 | - { |
|
| 320 | - global $wpdb; |
|
| 321 | - // get the state and country ids from the old row |
|
| 322 | - try { |
|
| 323 | - $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
| 324 | - $new_country_iso = $new_country['CNT_ISO']; |
|
| 325 | - } catch (EE_Error $exception) { |
|
| 326 | - $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 327 | - } |
|
| 328 | - try { |
|
| 329 | - $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
| 330 | - $new_state_id = $new_state['STA_ID']; |
|
| 331 | - } catch (EE_Error $exception) { |
|
| 332 | - $new_state_id = 0; |
|
| 333 | - } |
|
| 334 | - $cols_n_values = array( |
|
| 335 | - 'ATT_ID'=>$new_attendee_cpt_id, |
|
| 336 | - 'ATT_fname'=>stripslashes($old_attendee['fname']), |
|
| 337 | - 'ATT_lname'=>stripslashes($old_attendee['lname']), |
|
| 338 | - 'ATT_address'=>stripslashes($old_attendee['address']), |
|
| 339 | - 'ATT_address2'=>stripslashes($old_attendee['address2']), |
|
| 340 | - 'ATT_city'=>stripslashes($old_attendee['city']), |
|
| 341 | - 'STA_ID'=>$new_state_id, |
|
| 342 | - 'CNT_ISO'=>$new_country_iso, |
|
| 343 | - 'ATT_zip'=>stripslashes($old_attendee['zip']), |
|
| 344 | - 'ATT_email'=>stripslashes($old_attendee['email']), |
|
| 345 | - 'ATT_phone'=>stripslashes($old_attendee['phone']), |
|
| 346 | - ); |
|
| 347 | - $datatypes = array( |
|
| 348 | - '%d',// ATT_ID |
|
| 349 | - '%s',// ATT_fname |
|
| 350 | - '%s',// ATT_lname |
|
| 351 | - '%s',// ATT_address |
|
| 352 | - '%s',// ATT_address2 |
|
| 353 | - '%s',// ATT_city |
|
| 354 | - '%d',// STA_ID |
|
| 355 | - '%s',// CNT_ISO |
|
| 356 | - '%s',// ATT_zip |
|
| 357 | - '%s',// ATT_email |
|
| 358 | - '%s',// ATT_phone |
|
| 359 | - ); |
|
| 360 | - $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
| 361 | - if (! $success) { |
|
| 362 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
| 363 | - return 0; |
|
| 364 | - } |
|
| 365 | - $new_id = $wpdb->insert_id; |
|
| 366 | - return $new_id; |
|
| 367 | - } |
|
| 314 | + private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
| 315 | + { |
|
| 316 | + global $wpdb; |
|
| 317 | + // get the state and country ids from the old row |
|
| 318 | + try { |
|
| 319 | + $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
| 320 | + $new_country_iso = $new_country['CNT_ISO']; |
|
| 321 | + } catch (EE_Error $exception) { |
|
| 322 | + $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 323 | + } |
|
| 324 | + try { |
|
| 325 | + $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
| 326 | + $new_state_id = $new_state['STA_ID']; |
|
| 327 | + } catch (EE_Error $exception) { |
|
| 328 | + $new_state_id = 0; |
|
| 329 | + } |
|
| 330 | + $cols_n_values = array( |
|
| 331 | + 'ATT_ID'=>$new_attendee_cpt_id, |
|
| 332 | + 'ATT_fname'=>stripslashes($old_attendee['fname']), |
|
| 333 | + 'ATT_lname'=>stripslashes($old_attendee['lname']), |
|
| 334 | + 'ATT_address'=>stripslashes($old_attendee['address']), |
|
| 335 | + 'ATT_address2'=>stripslashes($old_attendee['address2']), |
|
| 336 | + 'ATT_city'=>stripslashes($old_attendee['city']), |
|
| 337 | + 'STA_ID'=>$new_state_id, |
|
| 338 | + 'CNT_ISO'=>$new_country_iso, |
|
| 339 | + 'ATT_zip'=>stripslashes($old_attendee['zip']), |
|
| 340 | + 'ATT_email'=>stripslashes($old_attendee['email']), |
|
| 341 | + 'ATT_phone'=>stripslashes($old_attendee['phone']), |
|
| 342 | + ); |
|
| 343 | + $datatypes = array( |
|
| 344 | + '%d',// ATT_ID |
|
| 345 | + '%s',// ATT_fname |
|
| 346 | + '%s',// ATT_lname |
|
| 347 | + '%s',// ATT_address |
|
| 348 | + '%s',// ATT_address2 |
|
| 349 | + '%s',// ATT_city |
|
| 350 | + '%d',// STA_ID |
|
| 351 | + '%s',// CNT_ISO |
|
| 352 | + '%s',// ATT_zip |
|
| 353 | + '%s',// ATT_email |
|
| 354 | + '%s',// ATT_phone |
|
| 355 | + ); |
|
| 356 | + $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
| 357 | + if (! $success) { |
|
| 358 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
| 359 | + return 0; |
|
| 360 | + } |
|
| 361 | + $new_id = $wpdb->insert_id; |
|
| 362 | + return $new_id; |
|
| 363 | + } |
|
| 368 | 364 | |
| 369 | - /** |
|
| 370 | - * Note: we don't necessarily create a new transaction for each attendee row. |
|
| 371 | - * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
| 372 | - * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
| 373 | - * @global type $wpdb |
|
| 374 | - * @param type $old_attendee |
|
| 375 | - * @return int new transaction id |
|
| 376 | - */ |
|
| 377 | - private function _insert_new_transaction($old_attendee) |
|
| 378 | - { |
|
| 379 | - global $wpdb; |
|
| 365 | + /** |
|
| 366 | + * Note: we don't necessarily create a new transaction for each attendee row. |
|
| 367 | + * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
| 368 | + * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
| 369 | + * @global type $wpdb |
|
| 370 | + * @param type $old_attendee |
|
| 371 | + * @return int new transaction id |
|
| 372 | + */ |
|
| 373 | + private function _insert_new_transaction($old_attendee) |
|
| 374 | + { |
|
| 375 | + global $wpdb; |
|
| 380 | 376 | |
| 381 | - // first: let's check for an existing transaction for this old attendee |
|
| 382 | - if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
| 383 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
| 384 | - } else { // non-primary attendee, so find its primary attendee's transaction |
|
| 385 | - $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
| 386 | - if (! $primary_attendee_old_id) { |
|
| 387 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
| 388 | - $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
| 389 | - } |
|
| 390 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
| 391 | - if (! $txn_id) { |
|
| 392 | - $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
| 393 | - $txn_id = 0; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - // if there isn't yet a transaction row for this, create one |
|
| 397 | - // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
| 398 | - // it ought to have SOME transaction, so we'll make one) |
|
| 399 | - if (! $txn_id) { |
|
| 400 | - // maps 3.1 payment stati onto 4.1 transaction stati |
|
| 401 | - $txn_status_mapping = array( |
|
| 402 | - 'Completed'=>'TCM', |
|
| 403 | - 'Pending'=>'TIN', |
|
| 404 | - 'Payment Declined'=>'TIN', |
|
| 405 | - 'Incomplete'=>'TIN', |
|
| 406 | - 'Not Completed'=>'TIN', |
|
| 407 | - 'Cancelled'=>'TIN', |
|
| 408 | - 'Declined'=>'TIN' |
|
| 409 | - ); |
|
| 410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 411 | - $cols_n_values = array( |
|
| 412 | - 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 413 | - 'TXN_total'=>floatval($old_attendee['total_cost']), |
|
| 414 | - 'TXN_paid'=>floatval($old_attendee['amount_pd']), |
|
| 415 | - 'STS_ID'=>$STS_ID, |
|
| 416 | - 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
|
| 417 | - ); |
|
| 418 | - $datatypes = array( |
|
| 419 | - '%s',// TXN_timestamp |
|
| 420 | - '%f',// TXN_total |
|
| 421 | - '%f',// TXN_paid |
|
| 422 | - '%s',// STS_ID |
|
| 423 | - '%s',// TXN_hash_salt |
|
| 424 | - ); |
|
| 425 | - $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
| 426 | - if (! $success) { |
|
| 427 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
| 428 | - return 0; |
|
| 429 | - } |
|
| 430 | - $txn_id = $wpdb->insert_id; |
|
| 431 | - } |
|
| 377 | + // first: let's check for an existing transaction for this old attendee |
|
| 378 | + if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
| 379 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
| 380 | + } else { // non-primary attendee, so find its primary attendee's transaction |
|
| 381 | + $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
| 382 | + if (! $primary_attendee_old_id) { |
|
| 383 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
| 384 | + $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
| 385 | + } |
|
| 386 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
| 387 | + if (! $txn_id) { |
|
| 388 | + $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
| 389 | + $txn_id = 0; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + // if there isn't yet a transaction row for this, create one |
|
| 393 | + // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
| 394 | + // it ought to have SOME transaction, so we'll make one) |
|
| 395 | + if (! $txn_id) { |
|
| 396 | + // maps 3.1 payment stati onto 4.1 transaction stati |
|
| 397 | + $txn_status_mapping = array( |
|
| 398 | + 'Completed'=>'TCM', |
|
| 399 | + 'Pending'=>'TIN', |
|
| 400 | + 'Payment Declined'=>'TIN', |
|
| 401 | + 'Incomplete'=>'TIN', |
|
| 402 | + 'Not Completed'=>'TIN', |
|
| 403 | + 'Cancelled'=>'TIN', |
|
| 404 | + 'Declined'=>'TIN' |
|
| 405 | + ); |
|
| 406 | + $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 407 | + $cols_n_values = array( |
|
| 408 | + 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 409 | + 'TXN_total'=>floatval($old_attendee['total_cost']), |
|
| 410 | + 'TXN_paid'=>floatval($old_attendee['amount_pd']), |
|
| 411 | + 'STS_ID'=>$STS_ID, |
|
| 412 | + 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
|
| 413 | + ); |
|
| 414 | + $datatypes = array( |
|
| 415 | + '%s',// TXN_timestamp |
|
| 416 | + '%f',// TXN_total |
|
| 417 | + '%f',// TXN_paid |
|
| 418 | + '%s',// STS_ID |
|
| 419 | + '%s',// TXN_hash_salt |
|
| 420 | + ); |
|
| 421 | + $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
| 422 | + if (! $success) { |
|
| 423 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
| 424 | + return 0; |
|
| 425 | + } |
|
| 426 | + $txn_id = $wpdb->insert_id; |
|
| 427 | + } |
|
| 432 | 428 | |
| 433 | - return $txn_id; |
|
| 434 | - } |
|
| 435 | - /** |
|
| 436 | - * Detects if the MER tables exist |
|
| 437 | - * @global type $wpdb |
|
| 438 | - * @return boolean |
|
| 439 | - */ |
|
| 440 | - private function _mer_tables_exist() |
|
| 441 | - { |
|
| 442 | - if ($this->_mer_tables_exist === null) { |
|
| 443 | - global $wpdb; |
|
| 429 | + return $txn_id; |
|
| 430 | + } |
|
| 431 | + /** |
|
| 432 | + * Detects if the MER tables exist |
|
| 433 | + * @global type $wpdb |
|
| 434 | + * @return boolean |
|
| 435 | + */ |
|
| 436 | + private function _mer_tables_exist() |
|
| 437 | + { |
|
| 438 | + if ($this->_mer_tables_exist === null) { |
|
| 439 | + global $wpdb; |
|
| 444 | 440 | |
| 445 | - if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
| 446 | - $this->_mer_tables_exist = false; |
|
| 447 | - } else { |
|
| 448 | - $this->_mer_tables_exist = true; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - return $this->_mer_tables_exist; |
|
| 452 | - } |
|
| 441 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
| 442 | + $this->_mer_tables_exist = false; |
|
| 443 | + } else { |
|
| 444 | + $this->_mer_tables_exist = true; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + return $this->_mer_tables_exist; |
|
| 448 | + } |
|
| 453 | 449 | |
| 454 | - /** |
|
| 455 | - * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
| 456 | - * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
| 457 | - * @global type $wpdb |
|
| 458 | - * @param type $old_attendee_row |
|
| 459 | - * @return string |
|
| 460 | - */ |
|
| 461 | - private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
| 462 | - { |
|
| 463 | - // need event default reg status and if pre_approval was required |
|
| 464 | - global $wpdb; |
|
| 465 | - $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
| 466 | - return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
| 467 | - $old_attendee_row['payment_status'], |
|
| 468 | - intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
| 469 | - ); |
|
| 470 | - } |
|
| 471 | - /** |
|
| 472 | - * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
| 473 | - * and returns an array of their IDs |
|
| 474 | - * @global type $wpdb |
|
| 475 | - * @param array $old_attendee |
|
| 476 | - * @param int $new_attendee_id |
|
| 477 | - * @param int $new_txn_id |
|
| 478 | - * @return array of new registratio ids |
|
| 479 | - */ |
|
| 480 | - private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
| 481 | - { |
|
| 482 | - global $wpdb; |
|
| 450 | + /** |
|
| 451 | + * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
| 452 | + * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
| 453 | + * @global type $wpdb |
|
| 454 | + * @param type $old_attendee_row |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
| 458 | + { |
|
| 459 | + // need event default reg status and if pre_approval was required |
|
| 460 | + global $wpdb; |
|
| 461 | + $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
| 462 | + return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
| 463 | + $old_attendee_row['payment_status'], |
|
| 464 | + intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
| 465 | + ); |
|
| 466 | + } |
|
| 467 | + /** |
|
| 468 | + * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
| 469 | + * and returns an array of their IDs |
|
| 470 | + * @global type $wpdb |
|
| 471 | + * @param array $old_attendee |
|
| 472 | + * @param int $new_attendee_id |
|
| 473 | + * @param int $new_txn_id |
|
| 474 | + * @return array of new registratio ids |
|
| 475 | + */ |
|
| 476 | + private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
| 477 | + { |
|
| 478 | + global $wpdb; |
|
| 483 | 479 | |
| 484 | - $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
| 485 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
| 486 | - if (! $new_event_id) { |
|
| 487 | - $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 488 | - } |
|
| 480 | + $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
| 481 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
| 482 | + if (! $new_event_id) { |
|
| 483 | + $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
| 484 | + } |
|
| 489 | 485 | |
| 490 | - $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
| 491 | - if (! $ticket_id) { |
|
| 492 | - $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
| 493 | - $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
| 494 | - } |
|
| 495 | - $regs_on_this_row = intval($old_attendee['quantity']); |
|
| 496 | - $new_regs = array(); |
|
| 497 | - // 4 cases we need to account for: |
|
| 498 | - // 1 old attendee_details row with a quantity of X (no mer) |
|
| 499 | - // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
| 500 | - // Y old attendee_details rows with a quantity of x (because of mer) |
|
| 501 | - // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
| 502 | - for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
| 503 | - // sum regs on older rows |
|
| 504 | - $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
| 505 | - $cols_n_values = array( |
|
| 506 | - 'EVT_ID'=>$new_event_id, |
|
| 507 | - 'ATT_ID'=>$new_attendee_id, |
|
| 508 | - 'TXN_ID'=>$new_txn_id, |
|
| 509 | - 'TKT_ID'=>$ticket_id, |
|
| 510 | - 'STS_ID'=>$STS_ID, |
|
| 511 | - 'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 512 | - 'REG_final_price'=>$old_attendee['final_price'], |
|
| 513 | - 'REG_session'=> substr($old_attendee['attendee_session'], 0, 44), |
|
| 514 | - 'REG_code'=>sanitize_key($old_attendee['registration_id']), |
|
| 515 | - 'REG_url_link'=> sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
| 516 | - 'REG_count'=>$regs_on_this_event_and_txn + $count, |
|
| 517 | - 'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
| 518 | - 'REG_att_is_going'=>true, |
|
| 519 | - 'REG_deleted'=>false |
|
| 520 | - ); |
|
| 521 | - $datatypes = array( |
|
| 522 | - '%d',// EVT_ID |
|
| 523 | - '%d',// ATT_ID |
|
| 524 | - '%d',// TXN_ID |
|
| 525 | - '%d',// TKT_ID |
|
| 526 | - '%s',// STS_ID |
|
| 527 | - '%s',// REG_date |
|
| 528 | - '%f',// REG_final_price |
|
| 529 | - '%s',// REG_session |
|
| 530 | - '%s',// REG_code |
|
| 531 | - '%s',// REG_url_link |
|
| 532 | - '%d',// REG_count |
|
| 533 | - '%d',// REG_group_size |
|
| 534 | - '%d',// REG_att_is_going |
|
| 535 | - '%d',// REG_deleted |
|
| 536 | - ); |
|
| 537 | - $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
| 538 | - if (! $success) { |
|
| 539 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
| 540 | - return 0; |
|
| 541 | - } |
|
| 542 | - $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
| 543 | - $new_regs[] = $wpdb->insert_id; |
|
| 544 | - } |
|
| 545 | - $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
| 546 | - return $new_regs; |
|
| 547 | - } |
|
| 486 | + $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
| 487 | + if (! $ticket_id) { |
|
| 488 | + $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
| 489 | + $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
| 490 | + } |
|
| 491 | + $regs_on_this_row = intval($old_attendee['quantity']); |
|
| 492 | + $new_regs = array(); |
|
| 493 | + // 4 cases we need to account for: |
|
| 494 | + // 1 old attendee_details row with a quantity of X (no mer) |
|
| 495 | + // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
| 496 | + // Y old attendee_details rows with a quantity of x (because of mer) |
|
| 497 | + // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
| 498 | + for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
| 499 | + // sum regs on older rows |
|
| 500 | + $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
| 501 | + $cols_n_values = array( |
|
| 502 | + 'EVT_ID'=>$new_event_id, |
|
| 503 | + 'ATT_ID'=>$new_attendee_id, |
|
| 504 | + 'TXN_ID'=>$new_txn_id, |
|
| 505 | + 'TKT_ID'=>$ticket_id, |
|
| 506 | + 'STS_ID'=>$STS_ID, |
|
| 507 | + 'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 508 | + 'REG_final_price'=>$old_attendee['final_price'], |
|
| 509 | + 'REG_session'=> substr($old_attendee['attendee_session'], 0, 44), |
|
| 510 | + 'REG_code'=>sanitize_key($old_attendee['registration_id']), |
|
| 511 | + 'REG_url_link'=> sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
| 512 | + 'REG_count'=>$regs_on_this_event_and_txn + $count, |
|
| 513 | + 'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
| 514 | + 'REG_att_is_going'=>true, |
|
| 515 | + 'REG_deleted'=>false |
|
| 516 | + ); |
|
| 517 | + $datatypes = array( |
|
| 518 | + '%d',// EVT_ID |
|
| 519 | + '%d',// ATT_ID |
|
| 520 | + '%d',// TXN_ID |
|
| 521 | + '%d',// TKT_ID |
|
| 522 | + '%s',// STS_ID |
|
| 523 | + '%s',// REG_date |
|
| 524 | + '%f',// REG_final_price |
|
| 525 | + '%s',// REG_session |
|
| 526 | + '%s',// REG_code |
|
| 527 | + '%s',// REG_url_link |
|
| 528 | + '%d',// REG_count |
|
| 529 | + '%d',// REG_group_size |
|
| 530 | + '%d',// REG_att_is_going |
|
| 531 | + '%d',// REG_deleted |
|
| 532 | + ); |
|
| 533 | + $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
| 534 | + if (! $success) { |
|
| 535 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
| 536 | + return 0; |
|
| 537 | + } |
|
| 538 | + $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
| 539 | + $new_regs[] = $wpdb->insert_id; |
|
| 540 | + } |
|
| 541 | + $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
| 542 | + return $new_regs; |
|
| 543 | + } |
|
| 548 | 544 | |
| 549 | - /** |
|
| 550 | - * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
| 551 | - * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
| 552 | - * the sold amounts as we go, and is less efficient than a single big query, |
|
| 553 | - * but its safer because we KNOW these regs have been added, rather than inferring |
|
| 554 | - * that they WILL be added (because the attendees stage runs nearly last during |
|
| 555 | - * the migration script) |
|
| 556 | - * @param type $new_ticket_id |
|
| 557 | - * @param type $sold |
|
| 558 | - * @param type $STS_ID |
|
| 559 | - * @return boolean whether they were successfully updated or not |
|
| 560 | - */ |
|
| 561 | - protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
| 562 | - { |
|
| 563 | - if ($STS_ID != 'RAP') { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - global $wpdb; |
|
| 567 | - $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
| 568 | - if ($success) { |
|
| 569 | - // get the ticket's datetimes, and increment them too |
|
| 570 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 545 | + /** |
|
| 546 | + * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
| 547 | + * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
| 548 | + * the sold amounts as we go, and is less efficient than a single big query, |
|
| 549 | + * but its safer because we KNOW these regs have been added, rather than inferring |
|
| 550 | + * that they WILL be added (because the attendees stage runs nearly last during |
|
| 551 | + * the migration script) |
|
| 552 | + * @param type $new_ticket_id |
|
| 553 | + * @param type $sold |
|
| 554 | + * @param type $STS_ID |
|
| 555 | + * @return boolean whether they were successfully updated or not |
|
| 556 | + */ |
|
| 557 | + protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
| 558 | + { |
|
| 559 | + if ($STS_ID != 'RAP') { |
|
| 560 | + return true; |
|
| 561 | + } |
|
| 562 | + global $wpdb; |
|
| 563 | + $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
| 564 | + if ($success) { |
|
| 565 | + // get the ticket's datetimes, and increment them too |
|
| 566 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 571 | 567 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
| 572 | 568 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
| 573 | 569 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
| 574 | - if (! $success_update_dateimtes) { |
|
| 575 | - $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
| 579 | - } |
|
| 580 | - return true; |
|
| 581 | - } |
|
| 582 | - /** |
|
| 583 | - * Makes a best guess at which ticket is the one the attendee purchased. |
|
| 584 | - * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
| 585 | - * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
| 586 | - * however, if we don't find an exact match, see if any of those conditions match; |
|
| 587 | - * and lastly if none of that works, just use the first ticket for the event we find |
|
| 588 | - * @param array $old_attendee |
|
| 589 | - */ |
|
| 590 | - private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
| 591 | - { |
|
| 592 | - global $wpdb; |
|
| 593 | - $tickets_table = $this->_new_ticket_table; |
|
| 594 | - $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
| 595 | - $datetime_table = $this->_new_datetime_table; |
|
| 570 | + if (! $success_update_dateimtes) { |
|
| 571 | + $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
| 575 | + } |
|
| 576 | + return true; |
|
| 577 | + } |
|
| 578 | + /** |
|
| 579 | + * Makes a best guess at which ticket is the one the attendee purchased. |
|
| 580 | + * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
| 581 | + * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
| 582 | + * however, if we don't find an exact match, see if any of those conditions match; |
|
| 583 | + * and lastly if none of that works, just use the first ticket for the event we find |
|
| 584 | + * @param array $old_attendee |
|
| 585 | + */ |
|
| 586 | + private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
| 587 | + { |
|
| 588 | + global $wpdb; |
|
| 589 | + $tickets_table = $this->_new_ticket_table; |
|
| 590 | + $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
| 591 | + $datetime_table = $this->_new_datetime_table; |
|
| 596 | 592 | |
| 597 | - $old_att_price_option = $old_attendee['price_option']; |
|
| 598 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
| 593 | + $old_att_price_option = $old_attendee['price_option']; |
|
| 594 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
| 599 | 595 | |
| 600 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 601 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 602 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 603 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 604 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
| 605 | - $conditions = array( |
|
| 606 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 607 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 608 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 609 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 610 | - ); |
|
| 611 | - $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
| 596 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 597 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 598 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 599 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
| 600 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
| 601 | + $conditions = array( |
|
| 602 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 603 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 604 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 605 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 606 | + ); |
|
| 607 | + $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
| 612 | 608 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
| 613 | 609 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
| 614 | - // start running queries, widening search each time by removing a condition |
|
| 615 | - do { |
|
| 616 | - $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 617 | - $ticket_id_found = $wpdb->get_var($full_query); |
|
| 618 | - array_shift($conditions); |
|
| 619 | - } while (! $ticket_id_found && $conditions); |
|
| 620 | - return $ticket_id_found; |
|
| 621 | - } |
|
| 610 | + // start running queries, widening search each time by removing a condition |
|
| 611 | + do { |
|
| 612 | + $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
| 613 | + $ticket_id_found = $wpdb->get_var($full_query); |
|
| 614 | + array_shift($conditions); |
|
| 615 | + } while (! $ticket_id_found && $conditions); |
|
| 616 | + return $ticket_id_found; |
|
| 617 | + } |
|
| 622 | 618 | |
| 623 | - /** |
|
| 624 | - * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
| 625 | - * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
| 626 | - * the new ticket to that datetime and price. |
|
| 627 | - * @return int ticket id |
|
| 628 | - */ |
|
| 629 | - private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
| 630 | - { |
|
| 631 | - global $wpdb; |
|
| 632 | - $old_att_price_option = $old_attendee['price_option']; |
|
| 633 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
| 619 | + /** |
|
| 620 | + * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
| 621 | + * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
| 622 | + * the new ticket to that datetime and price. |
|
| 623 | + * @return int ticket id |
|
| 624 | + */ |
|
| 625 | + private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
| 626 | + { |
|
| 627 | + global $wpdb; |
|
| 628 | + $old_att_price_option = $old_attendee['price_option']; |
|
| 629 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
| 634 | 630 | |
| 635 | - $old_att_start_date = $old_attendee['start_date']; |
|
| 636 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 637 | - $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 631 | + $old_att_start_date = $old_attendee['start_date']; |
|
| 632 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 633 | + $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
| 638 | 634 | |
| 639 | 635 | |
| 640 | - // insert new datetime unless we find one |
|
| 641 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
| 642 | - if (! $datetime_id) { |
|
| 643 | - $old_att_end_date = $old_attendee['start_date']; |
|
| 644 | - $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 645 | - $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
| 646 | - $wpdb->insert( |
|
| 647 | - $this->_new_datetime_table, |
|
| 648 | - array( |
|
| 649 | - 'EVT_ID' => $new_event_id, |
|
| 650 | - 'DTT_EVT_start' => $old_att_start_datetime, |
|
| 651 | - 'DTT_EVT_end' => $old_att_end_datetime, |
|
| 652 | - 'DTT_deleted' => true |
|
| 653 | - ), |
|
| 654 | - array( |
|
| 655 | - '%d',// EVT_ID |
|
| 656 | - '%s',// DTT_EVT_start |
|
| 657 | - '%s',// DTT_EVT_end |
|
| 658 | - '%d',// DTT_deleted |
|
| 659 | - ) |
|
| 660 | - ); |
|
| 661 | - $datetime_id = $wpdb->insert_id; |
|
| 662 | - } |
|
| 636 | + // insert new datetime unless we find one |
|
| 637 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
| 638 | + if (! $datetime_id) { |
|
| 639 | + $old_att_end_date = $old_attendee['start_date']; |
|
| 640 | + $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
| 641 | + $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
| 642 | + $wpdb->insert( |
|
| 643 | + $this->_new_datetime_table, |
|
| 644 | + array( |
|
| 645 | + 'EVT_ID' => $new_event_id, |
|
| 646 | + 'DTT_EVT_start' => $old_att_start_datetime, |
|
| 647 | + 'DTT_EVT_end' => $old_att_end_datetime, |
|
| 648 | + 'DTT_deleted' => true |
|
| 649 | + ), |
|
| 650 | + array( |
|
| 651 | + '%d',// EVT_ID |
|
| 652 | + '%s',// DTT_EVT_start |
|
| 653 | + '%s',// DTT_EVT_end |
|
| 654 | + '%d',// DTT_deleted |
|
| 655 | + ) |
|
| 656 | + ); |
|
| 657 | + $datetime_id = $wpdb->insert_id; |
|
| 658 | + } |
|
| 663 | 659 | |
| 664 | - // insert new ticket |
|
| 665 | - $success = $wpdb->insert( |
|
| 666 | - $wpdb->prefix . 'esp_ticket', |
|
| 667 | - array( |
|
| 668 | - 'TKT_name' => $old_att_price_option, |
|
| 669 | - 'TKT_qty' => -1, |
|
| 670 | - 'TKT_price' => $old_att_price, |
|
| 671 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
| 672 | - 'TKT_end_date' => $old_att_end_datetime, |
|
| 660 | + // insert new ticket |
|
| 661 | + $success = $wpdb->insert( |
|
| 662 | + $wpdb->prefix . 'esp_ticket', |
|
| 663 | + array( |
|
| 664 | + 'TKT_name' => $old_att_price_option, |
|
| 665 | + 'TKT_qty' => -1, |
|
| 666 | + 'TKT_price' => $old_att_price, |
|
| 667 | + 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
| 668 | + 'TKT_end_date' => $old_att_end_datetime, |
|
| 673 | 669 | |
| 674 | - ), |
|
| 675 | - array( |
|
| 676 | - '%s',// name |
|
| 677 | - '%d',// qty |
|
| 678 | - '%d',// price |
|
| 679 | - '%s',// start_date |
|
| 680 | - '%s',// end_date |
|
| 681 | - ) |
|
| 682 | - ); |
|
| 683 | - $ticket_id = $wpdb->insert_id; |
|
| 684 | - // associate the ticket with the datetime we found earlier |
|
| 685 | - $wpdb->insert( |
|
| 686 | - $this->_new_datetime_ticket_table, |
|
| 687 | - array( |
|
| 688 | - 'DTT_ID' => $datetime_id, |
|
| 689 | - 'TKT_ID' => $ticket_id |
|
| 690 | - ), |
|
| 691 | - array( |
|
| 692 | - '%d',// DTT_ID |
|
| 693 | - '%d',// TKT_ID |
|
| 694 | - ) |
|
| 695 | - ); |
|
| 696 | - // insert new price |
|
| 697 | - $wpdb->insert( |
|
| 698 | - $this->_new_price_table, |
|
| 699 | - array( |
|
| 700 | - 'PRC_amount' => $old_att_price, |
|
| 701 | - 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
| 702 | - 'PRC_name' => $old_att_price_option, |
|
| 703 | - 'PRC_deleted' => true |
|
| 704 | - ), |
|
| 705 | - array( |
|
| 706 | - '%d',// PRC_amount |
|
| 707 | - '%d',// PRT_ID |
|
| 708 | - '%s',// PRC_name |
|
| 709 | - '%d',// PRC_deleted |
|
| 710 | - ) |
|
| 711 | - ); |
|
| 712 | - $price_id = $wpdb->insert_id; |
|
| 713 | - // associate the price to the ticket |
|
| 714 | - $wpdb->insert( |
|
| 715 | - $this->_new_ticket_price_table, |
|
| 716 | - array( |
|
| 717 | - 'TKT_ID' => $ticket_id, |
|
| 718 | - 'PRC_ID' => $price_id |
|
| 719 | - ), |
|
| 720 | - array( |
|
| 721 | - '%d',// TKT_ID |
|
| 722 | - '%d',// PRC_ID |
|
| 723 | - ) |
|
| 724 | - ); |
|
| 725 | - return $ticket_id; |
|
| 726 | - } |
|
| 727 | - /** |
|
| 728 | - * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
| 729 | - * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
| 730 | - * @global type $wpdb |
|
| 731 | - * @param array $old_attendee_row |
|
| 732 | - * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
| 733 | - * @return int |
|
| 734 | - */ |
|
| 735 | - private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
| 736 | - { |
|
| 737 | - global $wpdb; |
|
| 738 | - $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
| 739 | - $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
| 670 | + ), |
|
| 671 | + array( |
|
| 672 | + '%s',// name |
|
| 673 | + '%d',// qty |
|
| 674 | + '%d',// price |
|
| 675 | + '%s',// start_date |
|
| 676 | + '%s',// end_date |
|
| 677 | + ) |
|
| 678 | + ); |
|
| 679 | + $ticket_id = $wpdb->insert_id; |
|
| 680 | + // associate the ticket with the datetime we found earlier |
|
| 681 | + $wpdb->insert( |
|
| 682 | + $this->_new_datetime_ticket_table, |
|
| 683 | + array( |
|
| 684 | + 'DTT_ID' => $datetime_id, |
|
| 685 | + 'TKT_ID' => $ticket_id |
|
| 686 | + ), |
|
| 687 | + array( |
|
| 688 | + '%d',// DTT_ID |
|
| 689 | + '%d',// TKT_ID |
|
| 690 | + ) |
|
| 691 | + ); |
|
| 692 | + // insert new price |
|
| 693 | + $wpdb->insert( |
|
| 694 | + $this->_new_price_table, |
|
| 695 | + array( |
|
| 696 | + 'PRC_amount' => $old_att_price, |
|
| 697 | + 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
| 698 | + 'PRC_name' => $old_att_price_option, |
|
| 699 | + 'PRC_deleted' => true |
|
| 700 | + ), |
|
| 701 | + array( |
|
| 702 | + '%d',// PRC_amount |
|
| 703 | + '%d',// PRT_ID |
|
| 704 | + '%s',// PRC_name |
|
| 705 | + '%d',// PRC_deleted |
|
| 706 | + ) |
|
| 707 | + ); |
|
| 708 | + $price_id = $wpdb->insert_id; |
|
| 709 | + // associate the price to the ticket |
|
| 710 | + $wpdb->insert( |
|
| 711 | + $this->_new_ticket_price_table, |
|
| 712 | + array( |
|
| 713 | + 'TKT_ID' => $ticket_id, |
|
| 714 | + 'PRC_ID' => $price_id |
|
| 715 | + ), |
|
| 716 | + array( |
|
| 717 | + '%d',// TKT_ID |
|
| 718 | + '%d',// PRC_ID |
|
| 719 | + ) |
|
| 720 | + ); |
|
| 721 | + return $ticket_id; |
|
| 722 | + } |
|
| 723 | + /** |
|
| 724 | + * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
| 725 | + * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
| 726 | + * @global type $wpdb |
|
| 727 | + * @param array $old_attendee_row |
|
| 728 | + * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
| 729 | + * @return int |
|
| 730 | + */ |
|
| 731 | + private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
| 732 | + { |
|
| 733 | + global $wpdb; |
|
| 734 | + $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
| 735 | + $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
| 740 | 736 | |
| 741 | - if ($this->_mer_tables_exist()) { |
|
| 742 | - // if MER exists, then its a little tricky. |
|
| 743 | - // when users registered by adding items to the cart, and it was a |
|
| 744 | - // group registration requiring additional attendee INFO, then the attendee rows |
|
| 745 | - // DO NOT have the same registration_id (although they probably should have) |
|
| 746 | - // they are related just like MER attendee rows are related, through the MER group table |
|
| 747 | - // BUT we want to count all the MER attendee rows for the same registration |
|
| 748 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
| 737 | + if ($this->_mer_tables_exist()) { |
|
| 738 | + // if MER exists, then its a little tricky. |
|
| 739 | + // when users registered by adding items to the cart, and it was a |
|
| 740 | + // group registration requiring additional attendee INFO, then the attendee rows |
|
| 741 | + // DO NOT have the same registration_id (although they probably should have) |
|
| 742 | + // they are related just like MER attendee rows are related, through the MER group table |
|
| 743 | + // BUT we want to count all the MER attendee rows for the same registration |
|
| 744 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
| 749 | 745 | |
| 750 | - $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
| 751 | - $count = max($count_using_mer_table, $count); |
|
| 752 | - } |
|
| 753 | - return $count; |
|
| 754 | - } |
|
| 755 | - private function _insert_new_payment($old_attendee, $new_txn_id) |
|
| 756 | - { |
|
| 757 | - global $wpdb; |
|
| 758 | - // only add a payment for primary attendees |
|
| 759 | - $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 760 | - // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 761 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 762 | - $pay_status_mapping = array( |
|
| 763 | - 'Completed'=>'PAP', |
|
| 764 | - 'Payment Declined'=>'PDC', |
|
| 765 | - 'Cancelled'=>'PCN', |
|
| 766 | - 'Declined'=>'PDC' |
|
| 767 | - ); |
|
| 768 | - $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 769 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
| 770 | - $cols_n_values = array( |
|
| 771 | - 'TXN_ID'=>$new_txn_id, |
|
| 772 | - 'STS_ID'=>$STS_ID, |
|
| 773 | - 'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 774 | - 'PAY_method'=>'CART', |
|
| 775 | - 'PAY_amount'=>$old_attendee['amount_pd'], |
|
| 776 | - 'PAY_gateway'=>$old_attendee['txn_type'], |
|
| 777 | - 'PAY_gateway_response'=>'', |
|
| 778 | - 'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32), |
|
| 779 | - 'PAY_via_admin'=>$by_admin, |
|
| 780 | - 'PAY_details'=>$old_attendee['transaction_details'] |
|
| 746 | + $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
| 747 | + $count = max($count_using_mer_table, $count); |
|
| 748 | + } |
|
| 749 | + return $count; |
|
| 750 | + } |
|
| 751 | + private function _insert_new_payment($old_attendee, $new_txn_id) |
|
| 752 | + { |
|
| 753 | + global $wpdb; |
|
| 754 | + // only add a payment for primary attendees |
|
| 755 | + $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 756 | + // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
| 757 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
| 758 | + $pay_status_mapping = array( |
|
| 759 | + 'Completed'=>'PAP', |
|
| 760 | + 'Payment Declined'=>'PDC', |
|
| 761 | + 'Cancelled'=>'PCN', |
|
| 762 | + 'Declined'=>'PDC' |
|
| 763 | + ); |
|
| 764 | + $by_admin = $old_attendee['payment'] == 'Admin'; |
|
| 765 | + $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
| 766 | + $cols_n_values = array( |
|
| 767 | + 'TXN_ID'=>$new_txn_id, |
|
| 768 | + 'STS_ID'=>$STS_ID, |
|
| 769 | + 'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
| 770 | + 'PAY_method'=>'CART', |
|
| 771 | + 'PAY_amount'=>$old_attendee['amount_pd'], |
|
| 772 | + 'PAY_gateway'=>$old_attendee['txn_type'], |
|
| 773 | + 'PAY_gateway_response'=>'', |
|
| 774 | + 'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32), |
|
| 775 | + 'PAY_via_admin'=>$by_admin, |
|
| 776 | + 'PAY_details'=>$old_attendee['transaction_details'] |
|
| 781 | 777 | |
| 782 | - ); |
|
| 783 | - $datatypes = array( |
|
| 784 | - '%d',// TXN_Id |
|
| 785 | - '%s',// STS_ID |
|
| 786 | - '%s',// PAY_timestamp |
|
| 787 | - '%s',// PAY_method |
|
| 788 | - '%f',// PAY_amount |
|
| 789 | - '%s',// PAY_gateway |
|
| 790 | - '%s',// PAY_gateway_response |
|
| 791 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 792 | - '%d',// PAY_via_admin |
|
| 793 | - '%s',// PAY_details |
|
| 794 | - ); |
|
| 795 | - $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 796 | - if (! $success) { |
|
| 797 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
| 798 | - return 0; |
|
| 799 | - } |
|
| 800 | - $new_id = $wpdb->insert_id; |
|
| 801 | - return $new_id; |
|
| 802 | - } else { |
|
| 803 | - return 0; |
|
| 804 | - } |
|
| 805 | - } |
|
| 778 | + ); |
|
| 779 | + $datatypes = array( |
|
| 780 | + '%d',// TXN_Id |
|
| 781 | + '%s',// STS_ID |
|
| 782 | + '%s',// PAY_timestamp |
|
| 783 | + '%s',// PAY_method |
|
| 784 | + '%f',// PAY_amount |
|
| 785 | + '%s',// PAY_gateway |
|
| 786 | + '%s',// PAY_gateway_response |
|
| 787 | + '%s',// PAY_txn_id_chq_nmbr |
|
| 788 | + '%d',// PAY_via_admin |
|
| 789 | + '%s',// PAY_details |
|
| 790 | + ); |
|
| 791 | + $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
| 792 | + if (! $success) { |
|
| 793 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
| 794 | + return 0; |
|
| 795 | + } |
|
| 796 | + $new_id = $wpdb->insert_id; |
|
| 797 | + return $new_id; |
|
| 798 | + } else { |
|
| 799 | + return 0; |
|
| 800 | + } |
|
| 801 | + } |
|
| 806 | 802 | |
| 807 | - /** |
|
| 808 | - * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 809 | - * @global type $wpdb |
|
| 810 | - * @param type $old_registration_id |
|
| 811 | - * @return array |
|
| 812 | - */ |
|
| 813 | - private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 814 | - { |
|
| 815 | - if (! $this->_mer_tables_exist()) { |
|
| 816 | - return false; |
|
| 817 | - } |
|
| 818 | - global $wpdb; |
|
| 819 | - $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
| 820 | - return $old_att_for_primary_reg; |
|
| 821 | - } |
|
| 803 | + /** |
|
| 804 | + * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
| 805 | + * @global type $wpdb |
|
| 806 | + * @param type $old_registration_id |
|
| 807 | + * @return array |
|
| 808 | + */ |
|
| 809 | + private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
| 810 | + { |
|
| 811 | + if (! $this->_mer_tables_exist()) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + global $wpdb; |
|
| 815 | + $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
| 816 | + return $old_att_for_primary_reg; |
|
| 817 | + } |
|
| 822 | 818 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $this->select_expression = 'att.*, e.event_status'; |
| 214 | 214 | // Only select attendees for events that aren't deleted. |
| 215 | 215 | $this->_extra_where_sql = 'AS att |
| 216 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
| 216 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
| 217 | 217 | WHERE e.event_status!="D"'; |
| 218 | 218 | $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
| 219 | 219 | $this->_new_attendee_cpt_table = $wpdb->posts; |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | { |
| 236 | 236 | // first check if there's already a new attendee with similar characteristics |
| 237 | 237 | $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
| 238 | - if (! $new_att_id) { |
|
| 238 | + if ( ! $new_att_id) { |
|
| 239 | 239 | $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
| 240 | - if (! $new_att_id) { |
|
| 240 | + if ( ! $new_att_id) { |
|
| 241 | 241 | // if we couldnt even make an attendee, abandon all hope |
| 242 | 242 | return false; |
| 243 | 243 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
| 250 | 250 | |
| 251 | 251 | $txn_id = $this->_insert_new_transaction($old_row); |
| 252 | - if (! $txn_id) { |
|
| 252 | + if ( ! $txn_id) { |
|
| 253 | 253 | // if we couldnt make the transaction, also abandon all hope |
| 254 | 254 | return false; |
| 255 | 255 | } |
@@ -283,31 +283,31 @@ discard block |
||
| 283 | 283 | { |
| 284 | 284 | global $wpdb; |
| 285 | 285 | $cols_n_values = array( |
| 286 | - 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name |
|
| 287 | - 'post_content'=>'',// ATT_bio |
|
| 288 | - 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug |
|
| 289 | - 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
| 290 | - 'post_excerpt'=>'',// ATT_short_bio |
|
| 291 | - 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
| 292 | - 'post_author'=>0,// ATT_author |
|
| 293 | - 'post_parent'=>0,// ATT_parent |
|
| 294 | - 'post_type'=>'espresso_attendees',// post_type |
|
| 286 | + 'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name |
|
| 287 | + 'post_content'=>'', // ATT_bio |
|
| 288 | + 'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug |
|
| 289 | + 'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created |
|
| 290 | + 'post_excerpt'=>'', // ATT_short_bio |
|
| 291 | + 'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified |
|
| 292 | + 'post_author'=>0, // ATT_author |
|
| 293 | + 'post_parent'=>0, // ATT_parent |
|
| 294 | + 'post_type'=>'espresso_attendees', // post_type |
|
| 295 | 295 | 'post_status'=>'publish'// status |
| 296 | 296 | ); |
| 297 | 297 | $datatypes = array( |
| 298 | - '%s',// ATT_full_name |
|
| 299 | - '%s',// ATT_bio |
|
| 300 | - '%s',// ATT_slug |
|
| 301 | - '%s',// ATT_created |
|
| 302 | - '%s',// ATT_short_bio |
|
| 303 | - '%s',// ATT_modified |
|
| 304 | - '%d',// ATT_author |
|
| 305 | - '%d',// ATT_parent |
|
| 306 | - '%s',// post_type |
|
| 307 | - '%s',// status |
|
| 298 | + '%s', // ATT_full_name |
|
| 299 | + '%s', // ATT_bio |
|
| 300 | + '%s', // ATT_slug |
|
| 301 | + '%s', // ATT_created |
|
| 302 | + '%s', // ATT_short_bio |
|
| 303 | + '%s', // ATT_modified |
|
| 304 | + '%d', // ATT_author |
|
| 305 | + '%d', // ATT_parent |
|
| 306 | + '%s', // post_type |
|
| 307 | + '%s', // status |
|
| 308 | 308 | ); |
| 309 | 309 | $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
| 310 | - if (! $success) { |
|
| 310 | + if ( ! $success) { |
|
| 311 | 311 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
| 312 | 312 | return 0; |
| 313 | 313 | } |
@@ -345,20 +345,20 @@ discard block |
||
| 345 | 345 | 'ATT_phone'=>stripslashes($old_attendee['phone']), |
| 346 | 346 | ); |
| 347 | 347 | $datatypes = array( |
| 348 | - '%d',// ATT_ID |
|
| 349 | - '%s',// ATT_fname |
|
| 350 | - '%s',// ATT_lname |
|
| 351 | - '%s',// ATT_address |
|
| 352 | - '%s',// ATT_address2 |
|
| 353 | - '%s',// ATT_city |
|
| 354 | - '%d',// STA_ID |
|
| 355 | - '%s',// CNT_ISO |
|
| 356 | - '%s',// ATT_zip |
|
| 357 | - '%s',// ATT_email |
|
| 358 | - '%s',// ATT_phone |
|
| 348 | + '%d', // ATT_ID |
|
| 349 | + '%s', // ATT_fname |
|
| 350 | + '%s', // ATT_lname |
|
| 351 | + '%s', // ATT_address |
|
| 352 | + '%s', // ATT_address2 |
|
| 353 | + '%s', // ATT_city |
|
| 354 | + '%d', // STA_ID |
|
| 355 | + '%s', // CNT_ISO |
|
| 356 | + '%s', // ATT_zip |
|
| 357 | + '%s', // ATT_email |
|
| 358 | + '%s', // ATT_phone |
|
| 359 | 359 | ); |
| 360 | 360 | $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
| 361 | - if (! $success) { |
|
| 361 | + if ( ! $success) { |
|
| 362 | 362 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
| 363 | 363 | return 0; |
| 364 | 364 | } |
@@ -383,12 +383,12 @@ discard block |
||
| 383 | 383 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
| 384 | 384 | } else { // non-primary attendee, so find its primary attendee's transaction |
| 385 | 385 | $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
| 386 | - if (! $primary_attendee_old_id) { |
|
| 386 | + if ( ! $primary_attendee_old_id) { |
|
| 387 | 387 | $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
| 388 | 388 | $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
| 389 | 389 | } |
| 390 | 390 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
| 391 | - if (! $txn_id) { |
|
| 391 | + if ( ! $txn_id) { |
|
| 392 | 392 | $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
| 393 | 393 | $txn_id = 0; |
| 394 | 394 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | // if there isn't yet a transaction row for this, create one |
| 397 | 397 | // (so even if it was a non-primary attendee with no EE3 primary attendee, |
| 398 | 398 | // it ought to have SOME transaction, so we'll make one) |
| 399 | - if (! $txn_id) { |
|
| 399 | + if ( ! $txn_id) { |
|
| 400 | 400 | // maps 3.1 payment stati onto 4.1 transaction stati |
| 401 | 401 | $txn_status_mapping = array( |
| 402 | 402 | 'Completed'=>'TCM', |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | 'Cancelled'=>'TIN', |
| 408 | 408 | 'Declined'=>'TIN' |
| 409 | 409 | ); |
| 410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
| 410 | + $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN'; |
|
| 411 | 411 | $cols_n_values = array( |
| 412 | 412 | 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
| 413 | 413 | 'TXN_total'=>floatval($old_attendee['total_cost']), |
@@ -416,14 +416,14 @@ discard block |
||
| 416 | 416 | 'TXN_hash_salt'=>$old_attendee['hashSalt'] |
| 417 | 417 | ); |
| 418 | 418 | $datatypes = array( |
| 419 | - '%s',// TXN_timestamp |
|
| 420 | - '%f',// TXN_total |
|
| 421 | - '%f',// TXN_paid |
|
| 422 | - '%s',// STS_ID |
|
| 423 | - '%s',// TXN_hash_salt |
|
| 419 | + '%s', // TXN_timestamp |
|
| 420 | + '%f', // TXN_total |
|
| 421 | + '%f', // TXN_paid |
|
| 422 | + '%s', // STS_ID |
|
| 423 | + '%s', // TXN_hash_salt |
|
| 424 | 424 | ); |
| 425 | 425 | $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
| 426 | - if (! $success) { |
|
| 426 | + if ( ! $success) { |
|
| 427 | 427 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
| 428 | 428 | return 0; |
| 429 | 429 | } |
@@ -483,12 +483,12 @@ discard block |
||
| 483 | 483 | |
| 484 | 484 | $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
| 485 | 485 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
| 486 | - if (! $new_event_id) { |
|
| 486 | + if ( ! $new_event_id) { |
|
| 487 | 487 | $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
| 491 | - if (! $ticket_id) { |
|
| 491 | + if ( ! $ticket_id) { |
|
| 492 | 492 | $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
| 493 | 493 | $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
| 494 | 494 | } |
@@ -519,23 +519,23 @@ discard block |
||
| 519 | 519 | 'REG_deleted'=>false |
| 520 | 520 | ); |
| 521 | 521 | $datatypes = array( |
| 522 | - '%d',// EVT_ID |
|
| 523 | - '%d',// ATT_ID |
|
| 524 | - '%d',// TXN_ID |
|
| 525 | - '%d',// TKT_ID |
|
| 526 | - '%s',// STS_ID |
|
| 527 | - '%s',// REG_date |
|
| 528 | - '%f',// REG_final_price |
|
| 529 | - '%s',// REG_session |
|
| 530 | - '%s',// REG_code |
|
| 531 | - '%s',// REG_url_link |
|
| 532 | - '%d',// REG_count |
|
| 533 | - '%d',// REG_group_size |
|
| 534 | - '%d',// REG_att_is_going |
|
| 535 | - '%d',// REG_deleted |
|
| 522 | + '%d', // EVT_ID |
|
| 523 | + '%d', // ATT_ID |
|
| 524 | + '%d', // TXN_ID |
|
| 525 | + '%d', // TKT_ID |
|
| 526 | + '%s', // STS_ID |
|
| 527 | + '%s', // REG_date |
|
| 528 | + '%f', // REG_final_price |
|
| 529 | + '%s', // REG_session |
|
| 530 | + '%s', // REG_code |
|
| 531 | + '%s', // REG_url_link |
|
| 532 | + '%d', // REG_count |
|
| 533 | + '%d', // REG_group_size |
|
| 534 | + '%d', // REG_att_is_going |
|
| 535 | + '%d', // REG_deleted |
|
| 536 | 536 | ); |
| 537 | 537 | $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
| 538 | - if (! $success) { |
|
| 538 | + if ( ! $success) { |
|
| 539 | 539 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
| 540 | 540 | return 0; |
| 541 | 541 | } |
@@ -567,11 +567,11 @@ discard block |
||
| 567 | 567 | $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
| 568 | 568 | if ($success) { |
| 569 | 569 | // get the ticket's datetimes, and increment them too |
| 570 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 570 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
| 571 | 571 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
| 572 | 572 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
| 573 | 573 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
| 574 | - if (! $success_update_dateimtes) { |
|
| 574 | + if ( ! $success_update_dateimtes) { |
|
| 575 | 575 | $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
| 576 | 576 | } |
| 577 | 577 | } else { |
@@ -603,10 +603,10 @@ discard block |
||
| 603 | 603 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
| 604 | 604 | // the most important condition should be last, as it will be array_shift'ed off last |
| 605 | 605 | $conditions = array( |
| 606 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
| 607 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
| 608 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
| 609 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
| 606 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
| 607 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match? |
|
| 608 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match? |
|
| 609 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
| 610 | 610 | ); |
| 611 | 611 | $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
| 612 | 612 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
| 617 | 617 | $ticket_id_found = $wpdb->get_var($full_query); |
| 618 | 618 | array_shift($conditions); |
| 619 | - } while (! $ticket_id_found && $conditions); |
|
| 619 | + }while ( ! $ticket_id_found && $conditions); |
|
| 620 | 620 | return $ticket_id_found; |
| 621 | 621 | } |
| 622 | 622 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | |
| 639 | 639 | |
| 640 | 640 | // insert new datetime unless we find one |
| 641 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
| 642 | - if (! $datetime_id) { |
|
| 641 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM ".$this->_new_datetime_table." WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
| 642 | + if ( ! $datetime_id) { |
|
| 643 | 643 | $old_att_end_date = $old_attendee['start_date']; |
| 644 | 644 | $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
| 645 | 645 | $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
@@ -652,10 +652,10 @@ discard block |
||
| 652 | 652 | 'DTT_deleted' => true |
| 653 | 653 | ), |
| 654 | 654 | array( |
| 655 | - '%d',// EVT_ID |
|
| 656 | - '%s',// DTT_EVT_start |
|
| 657 | - '%s',// DTT_EVT_end |
|
| 658 | - '%d',// DTT_deleted |
|
| 655 | + '%d', // EVT_ID |
|
| 656 | + '%s', // DTT_EVT_start |
|
| 657 | + '%s', // DTT_EVT_end |
|
| 658 | + '%d', // DTT_deleted |
|
| 659 | 659 | ) |
| 660 | 660 | ); |
| 661 | 661 | $datetime_id = $wpdb->insert_id; |
@@ -663,21 +663,21 @@ discard block |
||
| 663 | 663 | |
| 664 | 664 | // insert new ticket |
| 665 | 665 | $success = $wpdb->insert( |
| 666 | - $wpdb->prefix . 'esp_ticket', |
|
| 666 | + $wpdb->prefix.'esp_ticket', |
|
| 667 | 667 | array( |
| 668 | 668 | 'TKT_name' => $old_att_price_option, |
| 669 | 669 | 'TKT_qty' => -1, |
| 670 | 670 | 'TKT_price' => $old_att_price, |
| 671 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
| 671 | + 'TKT_start_date' => $old_att_start_datetime, // we really have no clue what the time should be, but at least it was available when they attended |
|
| 672 | 672 | 'TKT_end_date' => $old_att_end_datetime, |
| 673 | 673 | |
| 674 | 674 | ), |
| 675 | 675 | array( |
| 676 | - '%s',// name |
|
| 677 | - '%d',// qty |
|
| 678 | - '%d',// price |
|
| 679 | - '%s',// start_date |
|
| 680 | - '%s',// end_date |
|
| 676 | + '%s', // name |
|
| 677 | + '%d', // qty |
|
| 678 | + '%d', // price |
|
| 679 | + '%s', // start_date |
|
| 680 | + '%s', // end_date |
|
| 681 | 681 | ) |
| 682 | 682 | ); |
| 683 | 683 | $ticket_id = $wpdb->insert_id; |
@@ -689,8 +689,8 @@ discard block |
||
| 689 | 689 | 'TKT_ID' => $ticket_id |
| 690 | 690 | ), |
| 691 | 691 | array( |
| 692 | - '%d',// DTT_ID |
|
| 693 | - '%d',// TKT_ID |
|
| 692 | + '%d', // DTT_ID |
|
| 693 | + '%d', // TKT_ID |
|
| 694 | 694 | ) |
| 695 | 695 | ); |
| 696 | 696 | // insert new price |
@@ -703,10 +703,10 @@ discard block |
||
| 703 | 703 | 'PRC_deleted' => true |
| 704 | 704 | ), |
| 705 | 705 | array( |
| 706 | - '%d',// PRC_amount |
|
| 707 | - '%d',// PRT_ID |
|
| 708 | - '%s',// PRC_name |
|
| 709 | - '%d',// PRC_deleted |
|
| 706 | + '%d', // PRC_amount |
|
| 707 | + '%d', // PRT_ID |
|
| 708 | + '%s', // PRC_name |
|
| 709 | + '%d', // PRC_deleted |
|
| 710 | 710 | ) |
| 711 | 711 | ); |
| 712 | 712 | $price_id = $wpdb->insert_id; |
@@ -718,8 +718,8 @@ discard block |
||
| 718 | 718 | 'PRC_ID' => $price_id |
| 719 | 719 | ), |
| 720 | 720 | array( |
| 721 | - '%d',// TKT_ID |
|
| 722 | - '%d',// PRC_ID |
|
| 721 | + '%d', // TKT_ID |
|
| 722 | + '%d', // PRC_ID |
|
| 723 | 723 | ) |
| 724 | 724 | ); |
| 725 | 725 | return $ticket_id; |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | { |
| 757 | 757 | global $wpdb; |
| 758 | 758 | // only add a payment for primary attendees |
| 759 | - $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed'); |
|
| 759 | + $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
| 760 | 760 | // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
| 761 | 761 | if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
| 762 | 762 | $pay_status_mapping = array( |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | 'Declined'=>'PDC' |
| 767 | 767 | ); |
| 768 | 768 | $by_admin = $old_attendee['payment'] == 'Admin'; |
| 769 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
| 769 | + $STS_ID = isset($pay_status_mapping[$old_attendee['payment_status']]) ? $pay_status_mapping[$old_attendee['payment_status']] : 'PFL'; // IE, if we don't recognize the status, assume payment failed |
|
| 770 | 770 | $cols_n_values = array( |
| 771 | 771 | 'TXN_ID'=>$new_txn_id, |
| 772 | 772 | 'STS_ID'=>$STS_ID, |
@@ -781,19 +781,19 @@ discard block |
||
| 781 | 781 | |
| 782 | 782 | ); |
| 783 | 783 | $datatypes = array( |
| 784 | - '%d',// TXN_Id |
|
| 785 | - '%s',// STS_ID |
|
| 786 | - '%s',// PAY_timestamp |
|
| 787 | - '%s',// PAY_method |
|
| 788 | - '%f',// PAY_amount |
|
| 789 | - '%s',// PAY_gateway |
|
| 790 | - '%s',// PAY_gateway_response |
|
| 791 | - '%s',// PAY_txn_id_chq_nmbr |
|
| 792 | - '%d',// PAY_via_admin |
|
| 793 | - '%s',// PAY_details |
|
| 784 | + '%d', // TXN_Id |
|
| 785 | + '%s', // STS_ID |
|
| 786 | + '%s', // PAY_timestamp |
|
| 787 | + '%s', // PAY_method |
|
| 788 | + '%f', // PAY_amount |
|
| 789 | + '%s', // PAY_gateway |
|
| 790 | + '%s', // PAY_gateway_response |
|
| 791 | + '%s', // PAY_txn_id_chq_nmbr |
|
| 792 | + '%d', // PAY_via_admin |
|
| 793 | + '%s', // PAY_details |
|
| 794 | 794 | ); |
| 795 | 795 | $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
| 796 | - if (! $success) { |
|
| 796 | + if ( ! $success) { |
|
| 797 | 797 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
| 798 | 798 | return 0; |
| 799 | 799 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | */ |
| 813 | 813 | private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
| 814 | 814 | { |
| 815 | - if (! $this->_mer_tables_exist()) { |
|
| 815 | + if ( ! $this->_mer_tables_exist()) { |
|
| 816 | 816 | return false; |
| 817 | 817 | } |
| 818 | 818 | global $wpdb; |