@@ -11,69 +11,69 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CronManager |
| 13 | 13 | { |
| 14 | - protected LoaderInterface $loader; |
|
| 15 | - |
|
| 16 | - |
|
| 17 | - public function __construct(LoaderInterface $loader) |
|
| 18 | - { |
|
| 19 | - $this->loader = $loader; |
|
| 20 | - $this->registerDependencies(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - public function registerDependencies() |
|
| 25 | - { |
|
| 26 | - $cron_jobs = [ |
|
| 27 | - ExpiredTransactionCheck::class, |
|
| 28 | - GarbageCollection::class, |
|
| 29 | - UpdateTransactionsWithPayment::class, |
|
| 30 | - ]; |
|
| 31 | - foreach ($cron_jobs as $cronJob) { |
|
| 32 | - EE_Dependency_Map::register_dependencies( |
|
| 33 | - $cronJob, |
|
| 34 | - [LoaderInterface::class => EE_Dependency_Map::load_from_cache] |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - public function loadCronJobs() |
|
| 41 | - { |
|
| 42 | - $this->loadExpiredTransactionCheck(); |
|
| 43 | - $this->loadGarbageCollection(); |
|
| 44 | - $this->loadUpdateTransactionsWithPayment(); |
|
| 45 | - $this->loadMessagesScheduler(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - private function loadExpiredTransactionCheck() |
|
| 50 | - { |
|
| 51 | - /** @var ExpiredTransactionCheck $cron_job */ |
|
| 52 | - $cron_job = $this->loader->getShared(ExpiredTransactionCheck::class); |
|
| 53 | - $cron_job->setHooks(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - private function loadGarbageCollection() |
|
| 58 | - { |
|
| 59 | - /** @var GarbageCollection $cron_job */ |
|
| 60 | - $cron_job = $this->loader->getShared(GarbageCollection::class); |
|
| 61 | - $cron_job->setHooks(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - private function loadUpdateTransactionsWithPayment() |
|
| 66 | - { |
|
| 67 | - /** @var UpdateTransactionsWithPayment $cron_job */ |
|
| 68 | - $cron_job = $this->loader->getShared(UpdateTransactionsWithPayment::class); |
|
| 69 | - $cron_job->setHooks(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - private function loadMessagesScheduler() |
|
| 74 | - { |
|
| 75 | - /** @var EE_Messages_Scheduler $cron_job */ |
|
| 76 | - $cron_job = $this->loader->getShared(EE_Messages_Scheduler::class); |
|
| 77 | - $cron_job->setHooks(); |
|
| 78 | - } |
|
| 14 | + protected LoaderInterface $loader; |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + public function __construct(LoaderInterface $loader) |
|
| 18 | + { |
|
| 19 | + $this->loader = $loader; |
|
| 20 | + $this->registerDependencies(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + public function registerDependencies() |
|
| 25 | + { |
|
| 26 | + $cron_jobs = [ |
|
| 27 | + ExpiredTransactionCheck::class, |
|
| 28 | + GarbageCollection::class, |
|
| 29 | + UpdateTransactionsWithPayment::class, |
|
| 30 | + ]; |
|
| 31 | + foreach ($cron_jobs as $cronJob) { |
|
| 32 | + EE_Dependency_Map::register_dependencies( |
|
| 33 | + $cronJob, |
|
| 34 | + [LoaderInterface::class => EE_Dependency_Map::load_from_cache] |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + public function loadCronJobs() |
|
| 41 | + { |
|
| 42 | + $this->loadExpiredTransactionCheck(); |
|
| 43 | + $this->loadGarbageCollection(); |
|
| 44 | + $this->loadUpdateTransactionsWithPayment(); |
|
| 45 | + $this->loadMessagesScheduler(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + private function loadExpiredTransactionCheck() |
|
| 50 | + { |
|
| 51 | + /** @var ExpiredTransactionCheck $cron_job */ |
|
| 52 | + $cron_job = $this->loader->getShared(ExpiredTransactionCheck::class); |
|
| 53 | + $cron_job->setHooks(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + private function loadGarbageCollection() |
|
| 58 | + { |
|
| 59 | + /** @var GarbageCollection $cron_job */ |
|
| 60 | + $cron_job = $this->loader->getShared(GarbageCollection::class); |
|
| 61 | + $cron_job->setHooks(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + private function loadUpdateTransactionsWithPayment() |
|
| 66 | + { |
|
| 67 | + /** @var UpdateTransactionsWithPayment $cron_job */ |
|
| 68 | + $cron_job = $this->loader->getShared(UpdateTransactionsWithPayment::class); |
|
| 69 | + $cron_job->setHooks(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + private function loadMessagesScheduler() |
|
| 74 | + { |
|
| 75 | + /** @var EE_Messages_Scheduler $cron_job */ |
|
| 76 | + $cron_job = $this->loader->getShared(EE_Messages_Scheduler::class); |
|
| 77 | + $cron_job->setHooks(); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -6,64 +6,64 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CronUtilities |
| 8 | 8 | { |
| 9 | - public static function logScheduledEspressoCrons(): void |
|
| 10 | - { |
|
| 11 | - $ee_crons = [ |
|
| 12 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 13 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 14 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 15 | - ]; |
|
| 16 | - $crons = (array) get_option('cron'); |
|
| 17 | - foreach ($crons as $cron) { |
|
| 18 | - /** @var array[] $cron */ |
|
| 19 | - foreach ($ee_crons as $ee_cron) { |
|
| 20 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 21 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 22 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 23 | - if (! empty($ee_cron_details['args'])) { |
|
| 24 | - do_action( |
|
| 25 | - 'AHEE_log', |
|
| 26 | - __CLASS__, |
|
| 27 | - __FUNCTION__, |
|
| 28 | - print_r($ee_cron_details['args'], true), |
|
| 29 | - "$ee_cron args" |
|
| 30 | - ); |
|
| 31 | - } |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - } |
|
| 9 | + public static function logScheduledEspressoCrons(): void |
|
| 10 | + { |
|
| 11 | + $ee_crons = [ |
|
| 12 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 13 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 14 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 15 | + ]; |
|
| 16 | + $crons = (array) get_option('cron'); |
|
| 17 | + foreach ($crons as $cron) { |
|
| 18 | + /** @var array[] $cron */ |
|
| 19 | + foreach ($ee_crons as $ee_cron) { |
|
| 20 | + if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 21 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 22 | + foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 23 | + if (! empty($ee_cron_details['args'])) { |
|
| 24 | + do_action( |
|
| 25 | + 'AHEE_log', |
|
| 26 | + __CLASS__, |
|
| 27 | + __FUNCTION__, |
|
| 28 | + print_r($ee_cron_details['args'], true), |
|
| 29 | + "$ee_cron args" |
|
| 30 | + ); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 41 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 42 | - * |
|
| 43 | - * @param callable $cron_job |
|
| 44 | - * @param array $TXN_IDs |
|
| 45 | - * @return bool |
|
| 46 | - */ |
|
| 47 | - public static function rescheduleCronForTransactions(callable $cron_job, array $TXN_IDs): bool |
|
| 48 | - { |
|
| 49 | - // if database is accessible then return false so cron can run now |
|
| 50 | - if (DbStatus::isOnline()) { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - // reschedule the cron because we can't hit the db right now |
|
| 54 | - foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 55 | - // reset cron job for the TXN |
|
| 56 | - call_user_func_array( |
|
| 57 | - $cron_job, |
|
| 58 | - array_merge( |
|
| 59 | - [ |
|
| 60 | - time() + (10 * MINUTE_IN_SECONDS), |
|
| 61 | - $TXN_ID, |
|
| 62 | - ], |
|
| 63 | - (array) $additional_vars |
|
| 64 | - ) |
|
| 65 | - ); |
|
| 66 | - } |
|
| 67 | - return true; |
|
| 68 | - } |
|
| 39 | + /** |
|
| 40 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 41 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 42 | + * |
|
| 43 | + * @param callable $cron_job |
|
| 44 | + * @param array $TXN_IDs |
|
| 45 | + * @return bool |
|
| 46 | + */ |
|
| 47 | + public static function rescheduleCronForTransactions(callable $cron_job, array $TXN_IDs): bool |
|
| 48 | + { |
|
| 49 | + // if database is accessible then return false so cron can run now |
|
| 50 | + if (DbStatus::isOnline()) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + // reschedule the cron because we can't hit the db right now |
|
| 54 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 55 | + // reset cron job for the TXN |
|
| 56 | + call_user_func_array( |
|
| 57 | + $cron_job, |
|
| 58 | + array_merge( |
|
| 59 | + [ |
|
| 60 | + time() + (10 * MINUTE_IN_SECONDS), |
|
| 61 | + $TXN_ID, |
|
| 62 | + ], |
|
| 63 | + (array) $additional_vars |
|
| 64 | + ) |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
| 14 | 14 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
| 15 | 15 | ]; |
| 16 | - $crons = (array) get_option('cron'); |
|
| 16 | + $crons = (array) get_option('cron'); |
|
| 17 | 17 | foreach ($crons as $cron) { |
| 18 | 18 | /** @var array[] $cron */ |
| 19 | 19 | foreach ($ee_crons as $ee_cron) { |
| 20 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
| 20 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
| 21 | 21 | do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
| 22 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
| 23 | - if (! empty($ee_cron_details['args'])) { |
|
| 22 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
| 23 | + if ( ! empty($ee_cron_details['args'])) { |
|
| 24 | 24 | do_action( |
| 25 | 25 | 'AHEE_log', |
| 26 | 26 | __CLASS__, |
@@ -7,117 +7,117 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class CronSetup |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * constant used to indicate a cron task is no longer in use |
|
| 12 | - */ |
|
| 13 | - private const DEPRECATED = 'DEPRECATED'; |
|
| 10 | + /** |
|
| 11 | + * constant used to indicate a cron task is no longer in use |
|
| 12 | + */ |
|
| 13 | + private const DEPRECATED = 'DEPRECATED'; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Number of seconds between batch sends/generates on the cron job. |
|
| 17 | - * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
| 18 | - * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
| 19 | - * |
|
| 20 | - * @type int |
|
| 21 | - */ |
|
| 22 | - private const MESSAGE_CRON_SCHEDULE = 300; |
|
| 15 | + /** |
|
| 16 | + * Number of seconds between batch sends/generates on the cron job. |
|
| 17 | + * Defaults to 5 minutes in seconds. If you want to change this interval, you can use the native WordPress |
|
| 18 | + * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added. |
|
| 19 | + * |
|
| 20 | + * @type int |
|
| 21 | + */ |
|
| 22 | + private const MESSAGE_CRON_SCHEDULE = 300; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - public static function initialize() |
|
| 26 | - { |
|
| 27 | - CronSetup::removeCronTasks(); |
|
| 28 | - CronSetup::createCronTasks(); |
|
| 29 | - CronSetup::disabledCronCheck(); |
|
| 30 | - } |
|
| 25 | + public static function initialize() |
|
| 26 | + { |
|
| 27 | + CronSetup::removeCronTasks(); |
|
| 28 | + CronSetup::createCronTasks(); |
|
| 29 | + CronSetup::disabledCronCheck(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 34 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 35 | - * If the cron task should NO longer be used, it should have a value of InitialCronSetup::DEPRECATED |
|
| 36 | - * (null) |
|
| 37 | - * |
|
| 38 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 39 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 40 | - * @return array |
|
| 41 | - * @throws DomainException |
|
| 42 | - */ |
|
| 43 | - public static function getCronTasks(string $which_to_include): array |
|
| 44 | - { |
|
| 45 | - $cron_tasks = (array) apply_filters( |
|
| 46 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 47 | - [ |
|
| 48 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 49 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => CronSetup::DEPRECATED, |
|
| 50 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 51 | - ] |
|
| 52 | - ); |
|
| 53 | - if ($which_to_include === 'old') { |
|
| 54 | - return array_filter( |
|
| 55 | - $cron_tasks, |
|
| 56 | - function ($value) { |
|
| 57 | - return $value === CronSetup::DEPRECATED; |
|
| 58 | - } |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - if ($which_to_include === 'current') { |
|
| 62 | - return array_filter($cron_tasks); |
|
| 63 | - } |
|
| 64 | - if (WP_DEBUG && $which_to_include !== 'all') { |
|
| 65 | - throw new DomainException( |
|
| 66 | - sprintf( |
|
| 67 | - esc_html__( |
|
| 68 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 69 | - 'event_espresso' |
|
| 70 | - ), |
|
| 71 | - $which_to_include |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - return $cron_tasks; |
|
| 76 | - } |
|
| 32 | + /** |
|
| 33 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 34 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 35 | + * If the cron task should NO longer be used, it should have a value of InitialCronSetup::DEPRECATED |
|
| 36 | + * (null) |
|
| 37 | + * |
|
| 38 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 39 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 40 | + * @return array |
|
| 41 | + * @throws DomainException |
|
| 42 | + */ |
|
| 43 | + public static function getCronTasks(string $which_to_include): array |
|
| 44 | + { |
|
| 45 | + $cron_tasks = (array) apply_filters( |
|
| 46 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 47 | + [ |
|
| 48 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 49 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => CronSetup::DEPRECATED, |
|
| 50 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 51 | + ] |
|
| 52 | + ); |
|
| 53 | + if ($which_to_include === 'old') { |
|
| 54 | + return array_filter( |
|
| 55 | + $cron_tasks, |
|
| 56 | + function ($value) { |
|
| 57 | + return $value === CronSetup::DEPRECATED; |
|
| 58 | + } |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + if ($which_to_include === 'current') { |
|
| 62 | + return array_filter($cron_tasks); |
|
| 63 | + } |
|
| 64 | + if (WP_DEBUG && $which_to_include !== 'all') { |
|
| 65 | + throw new DomainException( |
|
| 66 | + sprintf( |
|
| 67 | + esc_html__( |
|
| 68 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 69 | + 'event_espresso' |
|
| 70 | + ), |
|
| 71 | + $which_to_include |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + return $cron_tasks; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Ensure cron tasks are set up (the removal of crons should be done by remove_crons()) |
|
| 81 | - * |
|
| 82 | - * @throws DomainException |
|
| 83 | - */ |
|
| 84 | - public static function createCronTasks() |
|
| 85 | - { |
|
| 86 | - $tasks = CronSetup::getCronTasks('current'); |
|
| 87 | - foreach ($tasks as $hook_name => $frequency) { |
|
| 88 | - if (! wp_next_scheduled($hook_name)) { |
|
| 89 | - /** |
|
| 90 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 91 | - */ |
|
| 92 | - if ( |
|
| 93 | - is_array($frequency) |
|
| 94 | - && count($frequency) === 2 |
|
| 95 | - && isset($frequency[0], $frequency[1]) |
|
| 96 | - ) { |
|
| 97 | - $start_timestamp = $frequency[0]; |
|
| 98 | - $frequency = $frequency[1]; |
|
| 99 | - } else { |
|
| 100 | - $start_timestamp = time(); |
|
| 101 | - } |
|
| 102 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - // also setup messages scheduler |
|
| 106 | - add_filter('cron_schedules', [CronSetup::class, 'espressoMessageSchedules']); |
|
| 107 | - } |
|
| 79 | + /** |
|
| 80 | + * Ensure cron tasks are set up (the removal of crons should be done by remove_crons()) |
|
| 81 | + * |
|
| 82 | + * @throws DomainException |
|
| 83 | + */ |
|
| 84 | + public static function createCronTasks() |
|
| 85 | + { |
|
| 86 | + $tasks = CronSetup::getCronTasks('current'); |
|
| 87 | + foreach ($tasks as $hook_name => $frequency) { |
|
| 88 | + if (! wp_next_scheduled($hook_name)) { |
|
| 89 | + /** |
|
| 90 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 91 | + */ |
|
| 92 | + if ( |
|
| 93 | + is_array($frequency) |
|
| 94 | + && count($frequency) === 2 |
|
| 95 | + && isset($frequency[0], $frequency[1]) |
|
| 96 | + ) { |
|
| 97 | + $start_timestamp = $frequency[0]; |
|
| 98 | + $frequency = $frequency[1]; |
|
| 99 | + } else { |
|
| 100 | + $start_timestamp = time(); |
|
| 101 | + } |
|
| 102 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + // also setup messages scheduler |
|
| 106 | + add_filter('cron_schedules', [CronSetup::class, 'espressoMessageSchedules']); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 112 | - * |
|
| 113 | - * @param bool $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 114 | - * @throws DomainException |
|
| 115 | - */ |
|
| 116 | - public static function removeCronTasks(bool $remove_all = true) |
|
| 117 | - { |
|
| 118 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 119 | - $crons = _get_cron_array(); |
|
| 120 | - /* reminder of what $crons look like: |
|
| 110 | + /** |
|
| 111 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 112 | + * |
|
| 113 | + * @param bool $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 114 | + * @throws DomainException |
|
| 115 | + */ |
|
| 116 | + public static function removeCronTasks(bool $remove_all = true) |
|
| 117 | + { |
|
| 118 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 119 | + $crons = _get_cron_array(); |
|
| 120 | + /* reminder of what $crons look like: |
|
| 121 | 121 | * Top-level keys are timestamps, and their values are arrays. |
| 122 | 122 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 123 | 123 | * and their values are arrays. |
@@ -134,73 +134,73 @@ discard block |
||
| 134 | 134 | * ... |
| 135 | 135 | * ... |
| 136 | 136 | */ |
| 137 | - $ee_cron_tasks_to_remove = CronSetup::getCronTasks($cron_tasks_to_remove); |
|
| 138 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 139 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 140 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 141 | - if ( |
|
| 142 | - isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 143 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 144 | - ) { |
|
| 145 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - // also take care of any empty cron timestamps. |
|
| 149 | - if (empty($hooks_to_fire_at_time)) { |
|
| 150 | - unset($crons[ $timestamp ]); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - _set_cron_array($crons); |
|
| 155 | - } |
|
| 137 | + $ee_cron_tasks_to_remove = CronSetup::getCronTasks($cron_tasks_to_remove); |
|
| 138 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 139 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 140 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 141 | + if ( |
|
| 142 | + isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 143 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 144 | + ) { |
|
| 145 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + // also take care of any empty cron timestamps. |
|
| 149 | + if (empty($hooks_to_fire_at_time)) { |
|
| 150 | + unset($crons[ $timestamp ]); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + _set_cron_array($crons); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @noinspection PhpUndefinedConstantInspection |
|
| 160 | - */ |
|
| 161 | - public static function disabledCronCheck() |
|
| 162 | - { |
|
| 163 | - // verify that WP Cron is enabled |
|
| 164 | - if ( |
|
| 165 | - defined('DISABLE_WP_CRON') |
|
| 166 | - && DISABLE_WP_CRON |
|
| 167 | - && is_admin() |
|
| 168 | - && ! get_option('ee_disabled_wp_cron_check') |
|
| 169 | - ) { |
|
| 170 | - /** |
|
| 171 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 172 | - * config is loaded. |
|
| 173 | - * This is intentionally using an anonymous function so that it's not easily de-registered. Client code |
|
| 174 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 175 | - * reverse any changes. |
|
| 176 | - */ |
|
| 177 | - add_action( |
|
| 178 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 179 | - function () { |
|
| 180 | - EE_Network_Config::instance()->core->do_messages_on_same_request = true; |
|
| 181 | - EE_Network_Config::instance()->update_config(true, false); |
|
| 182 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 183 | - } |
|
| 184 | - ); |
|
| 185 | - } |
|
| 186 | - } |
|
| 158 | + /** |
|
| 159 | + * @noinspection PhpUndefinedConstantInspection |
|
| 160 | + */ |
|
| 161 | + public static function disabledCronCheck() |
|
| 162 | + { |
|
| 163 | + // verify that WP Cron is enabled |
|
| 164 | + if ( |
|
| 165 | + defined('DISABLE_WP_CRON') |
|
| 166 | + && DISABLE_WP_CRON |
|
| 167 | + && is_admin() |
|
| 168 | + && ! get_option('ee_disabled_wp_cron_check') |
|
| 169 | + ) { |
|
| 170 | + /** |
|
| 171 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 172 | + * config is loaded. |
|
| 173 | + * This is intentionally using an anonymous function so that it's not easily de-registered. Client code |
|
| 174 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 175 | + * reverse any changes. |
|
| 176 | + */ |
|
| 177 | + add_action( |
|
| 178 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 179 | + function () { |
|
| 180 | + EE_Network_Config::instance()->core->do_messages_on_same_request = true; |
|
| 181 | + EE_Network_Config::instance()->update_config(true, false); |
|
| 182 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 183 | + } |
|
| 184 | + ); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Add custom schedules for wp_cron |
|
| 191 | - * |
|
| 192 | - * @param array $schedules |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - public static function espressoMessageSchedules(array $schedules): array |
|
| 196 | - { |
|
| 197 | - $schedules['ee_message_cron'] = [ |
|
| 198 | - 'interval' => CronSetup::MESSAGE_CRON_SCHEDULE, |
|
| 199 | - 'display' => esc_html__( |
|
| 200 | - 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
| 201 | - 'event_espresso' |
|
| 202 | - ), |
|
| 203 | - ]; |
|
| 204 | - return $schedules; |
|
| 205 | - } |
|
| 189 | + /** |
|
| 190 | + * Add custom schedules for wp_cron |
|
| 191 | + * |
|
| 192 | + * @param array $schedules |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + public static function espressoMessageSchedules(array $schedules): array |
|
| 196 | + { |
|
| 197 | + $schedules['ee_message_cron'] = [ |
|
| 198 | + 'interval' => CronSetup::MESSAGE_CRON_SCHEDULE, |
|
| 199 | + 'display' => esc_html__( |
|
| 200 | + 'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)', |
|
| 201 | + 'event_espresso' |
|
| 202 | + ), |
|
| 203 | + ]; |
|
| 204 | + return $schedules; |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public static function getCronTasks(string $which_to_include): array |
| 44 | 44 | { |
| 45 | - $cron_tasks = (array) apply_filters( |
|
| 45 | + $cron_tasks = (array) apply_filters( |
|
| 46 | 46 | 'FHEE__EEH_Activation__get_cron_tasks', |
| 47 | 47 | [ |
| 48 | 48 | 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if ($which_to_include === 'old') { |
| 54 | 54 | return array_filter( |
| 55 | 55 | $cron_tasks, |
| 56 | - function ($value) { |
|
| 56 | + function($value) { |
|
| 57 | 57 | return $value === CronSetup::DEPRECATED; |
| 58 | 58 | } |
| 59 | 59 | ); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | $tasks = CronSetup::getCronTasks('current'); |
| 87 | 87 | foreach ($tasks as $hook_name => $frequency) { |
| 88 | - if (! wp_next_scheduled($hook_name)) { |
|
| 88 | + if ( ! wp_next_scheduled($hook_name)) { |
|
| 89 | 89 | /** |
| 90 | 90 | * This allows client code to define the initial start timestamp for this schedule. |
| 91 | 91 | */ |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | if (is_array($hooks_to_fire_at_time)) { |
| 140 | 140 | foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
| 141 | 141 | if ( |
| 142 | - isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 143 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
| 142 | + isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 143 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 144 | 144 | ) { |
| 145 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
| 145 | + unset($crons[$timestamp][$hook_name]); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | // also take care of any empty cron timestamps. |
| 149 | 149 | if (empty($hooks_to_fire_at_time)) { |
| 150 | - unset($crons[ $timestamp ]); |
|
| 150 | + unset($crons[$timestamp]); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | add_action( |
| 178 | 178 | 'AHEE__EE_System__load_core_configuration__complete', |
| 179 | - function () { |
|
| 179 | + function() { |
|
| 180 | 180 | EE_Network_Config::instance()->core->do_messages_on_same_request = true; |
| 181 | 181 | EE_Network_Config::instance()->update_config(true, false); |
| 182 | 182 | add_option('ee_disabled_wp_cron_check', 1, '', false); |
@@ -9,62 +9,62 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class MaintenanceStatus |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Entire site is in maintenance mode |
|
| 14 | - */ |
|
| 15 | - public const FULL_SITE = 'FULL_SITE'; |
|
| 12 | + /** |
|
| 13 | + * Entire site is in maintenance mode |
|
| 14 | + */ |
|
| 15 | + public const FULL_SITE = 'FULL_SITE'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Frontend is in maintenance mode, but admin is available |
|
| 19 | - */ |
|
| 20 | - public const PUBLIC_ONLY = 'PUBLIC_ONLY'; |
|
| 17 | + /** |
|
| 18 | + * Frontend is in maintenance mode, but admin is available |
|
| 19 | + */ |
|
| 20 | + public const PUBLIC_ONLY = 'PUBLIC_ONLY'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Maintenance mode is disabled |
|
| 24 | - */ |
|
| 25 | - public const DISABLED = 'DISABLED'; |
|
| 22 | + /** |
|
| 23 | + * Maintenance mode is disabled |
|
| 24 | + */ |
|
| 25 | + public const DISABLED = 'DISABLED'; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - private static string $status = MaintenanceStatus::DISABLED; |
|
| 28 | + private static string $status = MaintenanceStatus::DISABLED; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - public static function isFullSite(): bool |
|
| 32 | - { |
|
| 33 | - return MaintenanceStatus::$status === MaintenanceStatus::FULL_SITE; |
|
| 34 | - } |
|
| 31 | + public static function isFullSite(): bool |
|
| 32 | + { |
|
| 33 | + return MaintenanceStatus::$status === MaintenanceStatus::FULL_SITE; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public static function isNotFullSite(): bool |
|
| 37 | - { |
|
| 38 | - return MaintenanceStatus::$status !== MaintenanceStatus::FULL_SITE; |
|
| 39 | - } |
|
| 36 | + public static function isNotFullSite(): bool |
|
| 37 | + { |
|
| 38 | + return MaintenanceStatus::$status !== MaintenanceStatus::FULL_SITE; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public static function isPublicOnly(): bool |
|
| 42 | - { |
|
| 43 | - return MaintenanceStatus::$status === MaintenanceStatus::PUBLIC_ONLY; |
|
| 44 | - } |
|
| 41 | + public static function isPublicOnly(): bool |
|
| 42 | + { |
|
| 43 | + return MaintenanceStatus::$status === MaintenanceStatus::PUBLIC_ONLY; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public static function isDisabled(): bool |
|
| 47 | - { |
|
| 48 | - return MaintenanceStatus::$status === MaintenanceStatus::DISABLED; |
|
| 49 | - } |
|
| 46 | + public static function isDisabled(): bool |
|
| 47 | + { |
|
| 48 | + return MaintenanceStatus::$status === MaintenanceStatus::DISABLED; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public static function isNotDisabled(): bool |
|
| 52 | - { |
|
| 53 | - return MaintenanceStatus::$status !== MaintenanceStatus::DISABLED; |
|
| 54 | - } |
|
| 51 | + public static function isNotDisabled(): bool |
|
| 52 | + { |
|
| 53 | + return MaintenanceStatus::$status !== MaintenanceStatus::DISABLED; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public static function setFullSiteMaintenanceMode(): void |
|
| 57 | - { |
|
| 58 | - MaintenanceStatus::$status = MaintenanceStatus::FULL_SITE; |
|
| 59 | - } |
|
| 56 | + public static function setFullSiteMaintenanceMode(): void |
|
| 57 | + { |
|
| 58 | + MaintenanceStatus::$status = MaintenanceStatus::FULL_SITE; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public static function setPublicOnlyMaintenanceMode(): void |
|
| 62 | - { |
|
| 63 | - MaintenanceStatus::$status = MaintenanceStatus::PUBLIC_ONLY; |
|
| 64 | - } |
|
| 61 | + public static function setPublicOnlyMaintenanceMode(): void |
|
| 62 | + { |
|
| 63 | + MaintenanceStatus::$status = MaintenanceStatus::PUBLIC_ONLY; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public static function disableMaintenanceMode(): void |
|
| 67 | - { |
|
| 68 | - MaintenanceStatus::$status = MaintenanceStatus::DISABLED; |
|
| 69 | - } |
|
| 66 | + public static function disableMaintenanceMode(): void |
|
| 67 | + { |
|
| 68 | + MaintenanceStatus::$status = MaintenanceStatus::DISABLED; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -9,39 +9,39 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class DbStatus |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Database is available for access and models can be used to query |
|
| 14 | - */ |
|
| 15 | - public const ONLINE = 'ONLINE'; |
|
| 12 | + /** |
|
| 13 | + * Database is available for access and models can be used to query |
|
| 14 | + */ |
|
| 15 | + public const ONLINE = 'ONLINE'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Database is unavailable for access and models cannot be used to query |
|
| 19 | - */ |
|
| 20 | - public const OFFLINE = 'OFFLINE'; |
|
| 17 | + /** |
|
| 18 | + * Database is unavailable for access and models cannot be used to query |
|
| 19 | + */ |
|
| 20 | + public const OFFLINE = 'OFFLINE'; |
|
| 21 | 21 | |
| 22 | - private static string $status = DbStatus::ONLINE; |
|
| 22 | + private static string $status = DbStatus::ONLINE; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - public static function isOnline(): bool |
|
| 26 | - { |
|
| 27 | - return DbStatus::$status === DbStatus::ONLINE; |
|
| 28 | - } |
|
| 25 | + public static function isOnline(): bool |
|
| 26 | + { |
|
| 27 | + return DbStatus::$status === DbStatus::ONLINE; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - public static function isOffline(): bool |
|
| 32 | - { |
|
| 33 | - return DbStatus::$status === DbStatus::OFFLINE; |
|
| 34 | - } |
|
| 31 | + public static function isOffline(): bool |
|
| 32 | + { |
|
| 33 | + return DbStatus::$status === DbStatus::OFFLINE; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - public static function setOnline(): void |
|
| 38 | - { |
|
| 39 | - DbStatus::$status = DbStatus::ONLINE; |
|
| 40 | - } |
|
| 37 | + public static function setOnline(): void |
|
| 38 | + { |
|
| 39 | + DbStatus::$status = DbStatus::ONLINE; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - public static function setOffline(): void |
|
| 44 | - { |
|
| 45 | - DbStatus::$status = DbStatus::OFFLINE; |
|
| 46 | - } |
|
| 43 | + public static function setOffline(): void |
|
| 44 | + { |
|
| 45 | + DbStatus::$status = DbStatus::OFFLINE; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -15,90 +15,90 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Domain extends DomainBase implements CaffeinatedInterface |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * URL path component used to denote an API request |
|
| 20 | - */ |
|
| 21 | - const API_NAMESPACE = 'ee/v'; |
|
| 22 | - |
|
| 23 | - const ASSET_NAMESPACE = 'eventespresso'; |
|
| 24 | - |
|
| 25 | - const TEXT_DOMAIN = 'event_espresso'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
| 29 | - * Page ui. |
|
| 30 | - */ |
|
| 31 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN = 'manual_registration_status_change_from_registration_admin'; |
|
| 32 | - |
|
| 33 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Whether or not EE core is the full premium version. |
|
| 38 | - * |
|
| 39 | - * @since 4.9.59.p |
|
| 40 | - * @var bool |
|
| 41 | - */ |
|
| 42 | - private bool $caffeinated = false; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @since 5.0.0.p |
|
| 46 | - * @var bool |
|
| 47 | - */ |
|
| 48 | - private bool $multisite; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - public function __construct(FilePath $plugin_file, Version $version) |
|
| 52 | - { |
|
| 53 | - parent::__construct($plugin_file, $version); |
|
| 54 | - $this->setCaffeinated(); |
|
| 55 | - $this->multisite = is_multisite(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Whether or not EE core is the full premium version. |
|
| 61 | - * |
|
| 62 | - * @return bool |
|
| 63 | - * @since 4.9.59.p |
|
| 64 | - */ |
|
| 65 | - public function isCaffeinated(): bool |
|
| 66 | - { |
|
| 67 | - return $this->caffeinated; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Setter for $is_caffeinated property. |
|
| 73 | - * |
|
| 74 | - * @since 4.9.59.p |
|
| 75 | - * @noinspection PhpUndefinedConstantInspection |
|
| 76 | - */ |
|
| 77 | - private function setCaffeinated() |
|
| 78 | - { |
|
| 79 | - $this->caffeinated = ! (defined('EE_DECAF') && EE_DECAF) |
|
| 80 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces |
|
| 86 | - * to allow for filtering the brand. |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public static function brandName(): string |
|
| 91 | - { |
|
| 92 | - return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return bool |
|
| 98 | - * @since 5.0.0.p |
|
| 99 | - */ |
|
| 100 | - public function isMultiSite(): bool |
|
| 101 | - { |
|
| 102 | - return $this->multisite; |
|
| 103 | - } |
|
| 18 | + /** |
|
| 19 | + * URL path component used to denote an API request |
|
| 20 | + */ |
|
| 21 | + const API_NAMESPACE = 'ee/v'; |
|
| 22 | + |
|
| 23 | + const ASSET_NAMESPACE = 'eventespresso'; |
|
| 24 | + |
|
| 25 | + const TEXT_DOMAIN = 'event_espresso'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
| 29 | + * Page ui. |
|
| 30 | + */ |
|
| 31 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN = 'manual_registration_status_change_from_registration_admin'; |
|
| 32 | + |
|
| 33 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Whether or not EE core is the full premium version. |
|
| 38 | + * |
|
| 39 | + * @since 4.9.59.p |
|
| 40 | + * @var bool |
|
| 41 | + */ |
|
| 42 | + private bool $caffeinated = false; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @since 5.0.0.p |
|
| 46 | + * @var bool |
|
| 47 | + */ |
|
| 48 | + private bool $multisite; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + public function __construct(FilePath $plugin_file, Version $version) |
|
| 52 | + { |
|
| 53 | + parent::__construct($plugin_file, $version); |
|
| 54 | + $this->setCaffeinated(); |
|
| 55 | + $this->multisite = is_multisite(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Whether or not EE core is the full premium version. |
|
| 61 | + * |
|
| 62 | + * @return bool |
|
| 63 | + * @since 4.9.59.p |
|
| 64 | + */ |
|
| 65 | + public function isCaffeinated(): bool |
|
| 66 | + { |
|
| 67 | + return $this->caffeinated; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Setter for $is_caffeinated property. |
|
| 73 | + * |
|
| 74 | + * @since 4.9.59.p |
|
| 75 | + * @noinspection PhpUndefinedConstantInspection |
|
| 76 | + */ |
|
| 77 | + private function setCaffeinated() |
|
| 78 | + { |
|
| 79 | + $this->caffeinated = ! (defined('EE_DECAF') && EE_DECAF) |
|
| 80 | + && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces |
|
| 86 | + * to allow for filtering the brand. |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public static function brandName(): string |
|
| 91 | + { |
|
| 92 | + return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return bool |
|
| 98 | + * @since 5.0.0.p |
|
| 99 | + */ |
|
| 100 | + public function isMultiSite(): bool |
|
| 101 | + { |
|
| 102 | + return $this->multisite; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | private function setCaffeinated() |
| 78 | 78 | { |
| 79 | 79 | $this->caffeinated = ! (defined('EE_DECAF') && EE_DECAF) |
| 80 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
| 80 | + && is_readable($this->pluginPath().'caffeinated/brewing_regular.php'); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -14,72 +14,72 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class GraphQLData implements GraphQLDataInterface |
| 16 | 16 | { |
| 17 | - public const QUERY_LIMIT = 250; |
|
| 17 | + public const QUERY_LIMIT = 250; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string $namespace The graphql namespace/prefix. |
|
| 21 | - */ |
|
| 22 | - protected string $namespace = 'Espresso'; |
|
| 19 | + /** |
|
| 20 | + * @var string $namespace The graphql namespace/prefix. |
|
| 21 | + */ |
|
| 22 | + protected string $namespace = 'Espresso'; |
|
| 23 | 23 | |
| 24 | - private array $params = []; |
|
| 24 | + private array $params = []; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param array $params |
|
| 29 | - */ |
|
| 30 | - public function setParams(array $params) |
|
| 31 | - { |
|
| 32 | - $this->params = $params; |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * @param array $params |
|
| 29 | + */ |
|
| 30 | + public function setParams(array $params) |
|
| 31 | + { |
|
| 32 | + $this->params = $params; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $field_key |
|
| 38 | - * @param array $where_params |
|
| 39 | - * @return mixed|null |
|
| 40 | - * @since 5.0.0.p |
|
| 41 | - */ |
|
| 42 | - protected function getQueryResponse(string $field_key, array $where_params = []) |
|
| 43 | - { |
|
| 44 | - if (! empty($where_params)) { |
|
| 45 | - if (! array_key_exists('variables', $this->params)) { |
|
| 46 | - $this->params['variables'] = []; |
|
| 47 | - } |
|
| 48 | - $this->params['variables']['where'] = $where_params; |
|
| 49 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $field_key |
|
| 38 | + * @param array $where_params |
|
| 39 | + * @return mixed|null |
|
| 40 | + * @since 5.0.0.p |
|
| 41 | + */ |
|
| 42 | + protected function getQueryResponse(string $field_key, array $where_params = []) |
|
| 43 | + { |
|
| 44 | + if (! empty($where_params)) { |
|
| 45 | + if (! array_key_exists('variables', $this->params)) { |
|
| 46 | + $this->params['variables'] = []; |
|
| 47 | + } |
|
| 48 | + $this->params['variables']['where'] = $where_params; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $responseData = $this->makeGraphQLRequest($this->params); |
|
| 52 | - return ! empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 53 | - } |
|
| 51 | + $responseData = $this->makeGraphQLRequest($this->params); |
|
| 52 | + return ! empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param array $data |
|
| 58 | - * @return array|null |
|
| 59 | - * @since 5.0.0.p |
|
| 60 | - */ |
|
| 61 | - protected function makeGraphQLRequest(array $data): ?array |
|
| 62 | - { |
|
| 63 | - $error = ''; |
|
| 64 | - try { |
|
| 65 | - $response = graphql($data); |
|
| 66 | - if (! empty($response['data'])) { |
|
| 67 | - return $response['data']; |
|
| 68 | - } |
|
| 69 | - $error = ! empty($response['errors']) |
|
| 70 | - ? print_r($response['errors'], true) |
|
| 71 | - : esc_html__( |
|
| 72 | - 'An unknown error has occurred during the GraphQL request and no data was found to return.', |
|
| 73 | - 'event_espresso' |
|
| 74 | - ); |
|
| 75 | - } catch (Exception $e) { |
|
| 76 | - if (defined('GRAPHQL_DEBUG') && GRAPHQL_DEBUG) { |
|
| 77 | - $error = $e->getMessage(); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($error !== '') { |
|
| 81 | - error_log($error); |
|
| 82 | - } |
|
| 83 | - return null; |
|
| 84 | - } |
|
| 56 | + /** |
|
| 57 | + * @param array $data |
|
| 58 | + * @return array|null |
|
| 59 | + * @since 5.0.0.p |
|
| 60 | + */ |
|
| 61 | + protected function makeGraphQLRequest(array $data): ?array |
|
| 62 | + { |
|
| 63 | + $error = ''; |
|
| 64 | + try { |
|
| 65 | + $response = graphql($data); |
|
| 66 | + if (! empty($response['data'])) { |
|
| 67 | + return $response['data']; |
|
| 68 | + } |
|
| 69 | + $error = ! empty($response['errors']) |
|
| 70 | + ? print_r($response['errors'], true) |
|
| 71 | + : esc_html__( |
|
| 72 | + 'An unknown error has occurred during the GraphQL request and no data was found to return.', |
|
| 73 | + 'event_espresso' |
|
| 74 | + ); |
|
| 75 | + } catch (Exception $e) { |
|
| 76 | + if (defined('GRAPHQL_DEBUG') && GRAPHQL_DEBUG) { |
|
| 77 | + $error = $e->getMessage(); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($error !== '') { |
|
| 81 | + error_log($error); |
|
| 82 | + } |
|
| 83 | + return null; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Event extends GraphQLData |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @inheritDoc |
|
| 9 | - */ |
|
| 10 | - public function getData(array $params = []): ?array |
|
| 11 | - { |
|
| 12 | - $field_key = lcfirst($this->namespace) . 'Event'; |
|
| 13 | - $query = <<<QUERY |
|
| 7 | + /** |
|
| 8 | + * @inheritDoc |
|
| 9 | + */ |
|
| 10 | + public function getData(array $params = []): ?array |
|
| 11 | + { |
|
| 12 | + $field_key = lcfirst($this->namespace) . 'Event'; |
|
| 13 | + $query = <<<QUERY |
|
| 14 | 14 | query GET_EVENT(\$id: ID!) { |
| 15 | 15 | $field_key(id: \$id, idType: DATABASE_ID) { |
| 16 | 16 | id |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | QUERY; |
| 51 | - $this->setParams( |
|
| 52 | - [ |
|
| 53 | - 'operation_name' => 'GET_EVENT', |
|
| 54 | - 'variables' => $params, |
|
| 55 | - 'query' => $query, |
|
| 56 | - ] |
|
| 57 | - ); |
|
| 51 | + $this->setParams( |
|
| 52 | + [ |
|
| 53 | + 'operation_name' => 'GET_EVENT', |
|
| 54 | + 'variables' => $params, |
|
| 55 | + 'query' => $query, |
|
| 56 | + ] |
|
| 57 | + ); |
|
| 58 | 58 | |
| 59 | - return $this->getQueryResponse($field_key); |
|
| 60 | - } |
|
| 59 | + return $this->getQueryResponse($field_key); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | public function getData(array $params = []): ?array |
| 11 | 11 | { |
| 12 | - $field_key = lcfirst($this->namespace) . 'Event'; |
|
| 12 | + $field_key = lcfirst($this->namespace).'Event'; |
|
| 13 | 13 | $query = <<<QUERY |
| 14 | 14 | query GET_EVENT(\$id: ID!) { |
| 15 | 15 | $field_key(id: \$id, idType: DATABASE_ID) { |
@@ -12,15 +12,15 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class PriceTypes extends GraphQLData |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @param array $where_params |
|
| 17 | - * @return array|null |
|
| 18 | - * @since 5.0.0.p |
|
| 19 | - */ |
|
| 20 | - public function getData(array $where_params = []): ?array |
|
| 21 | - { |
|
| 22 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 23 | - $query = <<<QUERY |
|
| 15 | + /** |
|
| 16 | + * @param array $where_params |
|
| 17 | + * @return array|null |
|
| 18 | + * @since 5.0.0.p |
|
| 19 | + */ |
|
| 20 | + public function getData(array $where_params = []): ?array |
|
| 21 | + { |
|
| 22 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 23 | + $query = <<<QUERY |
|
| 24 | 24 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
| 25 | 25 | $field_key(first: \$first, last: \$last) { |
| 26 | 26 | nodes { |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | QUERY; |
| 44 | - $this->setParams([ |
|
| 45 | - 'operation_name' => 'GET_PRICE_TYPES', |
|
| 46 | - 'variables' => [ |
|
| 47 | - 'first' => GraphQLData::QUERY_LIMIT, |
|
| 48 | - ], |
|
| 49 | - 'query' => $query, |
|
| 50 | - ]); |
|
| 44 | + $this->setParams([ |
|
| 45 | + 'operation_name' => 'GET_PRICE_TYPES', |
|
| 46 | + 'variables' => [ |
|
| 47 | + 'first' => GraphQLData::QUERY_LIMIT, |
|
| 48 | + ], |
|
| 49 | + 'query' => $query, |
|
| 50 | + ]); |
|
| 51 | 51 | |
| 52 | - return $this->getQueryResponse($field_key, $where_params); |
|
| 53 | - } |
|
| 52 | + return $this->getQueryResponse($field_key, $where_params); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function getData(array $where_params = []): ?array |
| 21 | 21 | { |
| 22 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
| 22 | + $field_key = lcfirst($this->namespace).'PriceTypes'; |
|
| 23 | 23 | $query = <<<QUERY |
| 24 | 24 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
| 25 | 25 | $field_key(first: \$first, last: \$last) { |