locked.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | use WPStaging\Core\WPStaging; |
| 4 | use WPStaging\Framework\Job\JobTransientCache; |
| 5 | use WPStaging\Framework\Job\Exception\ProcessLockedException; |
| 6 | use WPStaging\Framework\Job\ProcessLock; |
| 7 | |
| 8 | $processLock = WPStaging::make(ProcessLock::class); |
| 9 | $jobData = WPStaging::make(JobTransientCache::class)->getJob(); |
| 10 | $isLocked = false; |
| 11 | |
| 12 | try { |
| 13 | $processLock->checkProcessLocked(); |
| 14 | $isLocked = isset($jobData['status']) && $jobData['status'] === JobTransientCache::STATUS_RUNNING; |
| 15 | } catch (ProcessLockedException $e) { |
| 16 | $isLocked = true; |
| 17 | } |
| 18 | |
| 19 | if ($isLocked) { |
| 20 | $isDataAvailable = !empty($jobData); |
| 21 | $isCancelable = $jobData['status'] === JobTransientCache::STATUS_RUNNING; |
| 22 | ?> |
| 23 | <div id="wpstg--locked-process" class="wpstg--locked-process wpstg-flex wpstg-items-center wpstg-justify-between wpstg-gap-4 wpstg-rounded-lg wpstg-border wpstg-border-slate-200/70 dark:wpstg-border-white/10 wpstg-bg-white dark:wpstg-bg-dark-boxes wpstg-shadow-sm wpstg-px-5 wpstg-py-4" |
| 24 | <?php if ($isDataAvailable) : ?> |
| 25 | data-wpstg-started-at="<?php echo esc_attr($jobData['startedAt']); ?>" |
| 26 | data-wpstg-job-type="<?php echo esc_attr($jobData['type']); ?>" |
| 27 | data-wpstg-job-id="<?php echo esc_attr($jobData['jobId']); ?>" |
| 28 | <?php endif; ?> |
| 29 | > |
| 30 | <div class="wpstg--locked-process--body wpstg-flex wpstg-flex-1 wpstg-items-center wpstg-gap-4 wpstg-min-w-0"> |
| 31 | <div class="wpstg--locked-process--loader wpstg-shrink-0"></div> |
| 32 | <div class="wpstg--locked-process--content wpstg-flex-1 wpstg-min-w-0"> |
| 33 | <?php if ($isDataAvailable) : ?> |
| 34 | <div class="wpstg--locked-process--content--job wpstg-flex wpstg-items-start wpstg-justify-between wpstg-gap-4"> |
| 35 | <div class="wpstg-flex wpstg-flex-col wpstg-gap-0.5 wpstg-min-w-0"> |
| 36 | <span class="wpstg--locked-process--task-title wpstg-text-base wpstg-font-semibold wpstg-leading-tight wpstg-text-slate-900 dark:wpstg-text-slate-100"><?php esc_html_e('Processing...', 'wp-staging'); ?></span> |
| 37 | <span class="wpstg--locked-process--job-title wpstg-text-sm wpstg-text-slate-500 dark:wpstg-text-slate-400 wpstg-leading-tight"><?php echo esc_html($jobData['title']); ?></span> |
| 38 | </div> |
| 39 | <div class="wpstg-flex wpstg-flex-col wpstg-items-end wpstg-gap-0.5 wpstg-text-sm wpstg-text-slate-600 dark:wpstg-text-slate-300"> |
| 40 | <span class="wpstg--locked-process--timer wpstg-inline-flex wpstg-items-center wpstg-gap-1"> |
| 41 | <svg class="wpstg-text-slate-400" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 7l-1.343 1.343m0 0A8 8 0 1 0 6.343 19.657A8 8 0 0 0 17.657 8.343M12 10v4M9 3h6"/></svg> |
| 42 | <span class="wpstg--locked-process--elapsed-time wpstg-font-medium">00:00</span> |
| 43 | </span> |
| 44 | <span class="wpstg-font-medium"><span class="wpstg--locked-process--percentage">0</span>%</span> |
| 45 | </div> |
| 46 | </div> |
| 47 | <div class="wpstg--locked-process--content--task wpstg-mt-2 wpstg-block"> |
| 48 | <div class="wpstg-h-1.5 wpstg-w-full wpstg-rounded-full wpstg-bg-slate-200 dark:wpstg-bg-white/10" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-label="<?php esc_attr_e('Job progress', 'wp-staging'); ?>"> |
| 49 | <div class="wpstg--locked-process--progress-bar wpstg-h-full wpstg-rounded-full wpstg-bg-blue-600 dark:wpstg-bg-blue-500" style="width:0%"></div> |
| 50 | </div> |
| 51 | </div> |
| 52 | <?php endif; ?> |
| 53 | <?php if (!$isDataAvailable) : ?> |
| 54 | <span class="wpstg--locked-process--task-title wpstg-text-sm wpstg-leading-snug wpstg-text-slate-600"><?php esc_html_e('A WP Staging Job might be in progress. This message should disappear in few minutes. If you continue to see this message, contact the support!', 'wp-staging'); ?></span> |
| 55 | <?php endif; ?> |
| 56 | </div> |
| 57 | </div> |
| 58 | <?php |
| 59 | // A cancel job should not be cancelled, also let avoid showing logs modal for cancel jobs |
| 60 | if ($isDataAvailable && $jobData['type'] !== JobTransientCache::JOB_TYPE_CANCEL) : ?> |
| 61 | <div class="wpstg--locked-process--footer wpstg-flex wpstg-items-center wpstg-gap-3 wpstg-shrink-0"> |
| 62 | <button class="wpstg--locked-process--btn wpstg--locked-process--show-logs wpstg-btn wpstg-btn-md wpstg-btn-secondary"><?php esc_html_e('View live logs', 'wp-staging'); ?></button> |
| 63 | <?php |
| 64 | // Lets show cancel button only when it is cancellable |
| 65 | if ($isCancelable) : ?> |
| 66 | <button class="wpstg--locked-process--btn wpstg--locked-process--cancel-job wpstg-btn wpstg-btn-md wpstg-btn-danger"><?php esc_html_e('Cancel', 'wp-staging'); ?></button> |
| 67 | <?php endif; ?> |
| 68 | </div> |
| 69 | <?php endif; ?> |
| 70 | </div> |
| 71 | <?php |
| 72 | // as explained above, we only show the cancel modal if the job is cancellable |
| 73 | if ($isCancelable) : |
| 74 | require_once WPSTG_VIEWS_DIR . 'job/modal/confirm-cancel.php'; |
| 75 | endif; |
| 76 | } |
| 77 |