コード例 #1
0
 /**
  * Fixes environment once event occurs
  *
  * @param Config  $config
  * @param string  $event
  * @param Config|null $old_config
  * @throws Util_Environment_Exceptions
  */
 public function fix_on_event($config, $event, $old_config = null)
 {
     if ($config->get_boolean('cdn.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.queue.interval') != $old_config->get_integer('cdn.queue.interval')) {
             $this->unschedule_queue_process();
         }
         if (!wp_next_scheduled('w3_cdn_cron_queue_process')) {
             wp_schedule_event(time(), 'w3_cdn_cron_queue_process', 'w3_cdn_cron_queue_process');
         }
     } else {
         $this->unschedule_queue_process();
     }
     if ($config->get_boolean('cdn.enabled') && $config->get_boolean('cdn.autoupload.enabled') && !Cdn_Util::is_engine_mirror($config->get_string('cdn.engine'))) {
         if ($old_config != null && $config->get_integer('cdn.autoupload.interval') != $old_config->get_integer('cdn.autoupload.interval')) {
             $this->unschedule_upload();
         }
         if (!wp_next_scheduled('w3_cdn_cron_upload')) {
             wp_schedule_event(time(), 'w3_cdn_cron_upload', 'w3_cdn_cron_upload');
         }
     } else {
         $this->unschedule_upload();
     }
     $exs = new Util_Environment_Exceptions();
     if ($config->get_boolean('cdn.enabled')) {
         try {
             $this->table_create($event == 'activate');
         } catch (\Exception $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
コード例 #2
0
 /**
  * Fixes environment after plugin deactivation
  *
  * @throws Util_Environment_Exceptions
  * @return array
  */
 public function fix_after_deactivation()
 {
     $exs = new Util_Environment_Exceptions();
     try {
         $this->delete_addin();
     } catch (Util_WpFile_FilesystemOperationException $ex) {
         $exs->push($ex);
     }
     $this->unschedule();
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
コード例 #3
0
 /**
  * Used to display Util_Environment_Exceptions in UI
  *
  * @param Util_Environment_Exceptions $exs
  * @return array(before_errors = [], required_changes =>, later_errors => [])
  */
 public static function parse_environment_exceptions($exs)
 {
     $exceptions = $exs->exceptions();
     $commands = '';
     $required_changes = '';
     $before_errors = array();
     $later_errors = array();
     $operation_error_already_shown = false;
     foreach ($exceptions as $ex) {
         if ($ex instanceof Util_WpFile_FilesystemOperationException) {
             if (!$operation_error_already_shown) {
                 $m = $ex->getMessage();
                 if (strlen($m) > 0) {
                     $before_errors[] = $m;
                     // if multiple operations failed when
                     // they tried to fix environment - show only first
                     // otherwise can duplication information about
                     // absense of permissions
                     $operation_error_already_shown = true;
                 }
                 if ($ex instanceof Util_WpFile_FilesystemWriteException) {
                     $required_changes .= sprintf(__('Create the <strong>%s</strong> file and paste the following text into it:
                     <textarea>%s</textarea> <br />', 'w3-total-cache'), $ex->filename(), esc_textarea($ex->file_contents()));
                 } else {
                     if ($ex instanceof Util_WpFile_FilesystemModifyException) {
                         $modification_content = $ex->file_contents();
                         if (strlen($modification_content) > 0) {
                             $modification_content = '<textarea style="height: 100px; width: 100%;">' . esc_textarea($modification_content) . '</textarea>';
                         }
                         $required_changes .= $ex->modification_description() . $modification_content . '<br />';
                     } else {
                         if ($ex instanceof Util_WpFile_FilesystemCopyException) {
                             $commands .= 'cp ' . $ex->source_filename() . ' ' . $ex->destination_filename() . '<br />';
                         } else {
                             if ($ex instanceof Util_WpFile_FilesystemMkdirException) {
                                 $commands .= 'mkdir ' . $ex->folder() . '<br />';
                                 $commands .= 'chmod 777 ' . $ex->folder() . '<br />';
                             } else {
                                 if ($ex instanceof Util_WpFile_FilesystemRmException) {
                                     $commands .= 'rm ' . $ex->filename() . '<br />';
                                 } else {
                                     if ($ex instanceof Util_WpFile_FilesystemRmdirException) {
                                         $commands .= 'rm -rf ' . $ex->folder() . '<br />';
                                     } else {
                                         if ($ex instanceof Util_WpFile_FilesystemChmodException) {
                                             $commands .= 'chmod 777 ' . $ex->filename() . '<br />';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($ex instanceof Util_Environment_Exception) {
                 $t = $ex->technical_message();
                 if (strlen($t) > 0) {
                     $t = '<br />' . '<a class="w3tc_read_technical_info" href="#">' . __('Technical info', 'w3-total-cache') . '</a>' . '<div class="w3tc_technical_info" style="display: none">' . $t . '</div>';
                 }
                 $later_errors[] = $ex->getMessage() . $t;
             } else {
                 // unknown command
                 $later_errors[] = $ex->getMessage();
             }
         }
     }
     if (strlen($commands) > 0) {
         $required_changes .= __('Execute next commands in a shell:', 'w3-total-cache') . '<br><strong>' . $commands . '</strong>';
     }
     return array('before_errors' => $before_errors, 'required_changes' => $required_changes, 'later_errors' => $later_errors);
 }
コード例 #4
0
 /**
  * Fixes environment after plugin deactivation
  *
  * @param Config  $config
  * @throws Util_Environment_Exceptions
  */
 public function fix_after_deactivation($config)
 {
     $exs = new Util_Environment_Exceptions();
     // call plugin-related handlers
     foreach ($this->get_handlers($config) as $h) {
         try {
             $h->fix_after_deactivation();
         } catch (Util_Environment_Exceptions $ex) {
             $exs->push($ex);
         }
     }
     try {
         do_action('w3tc_environment_fix_after_deactivation', $config);
     } catch (Util_Environment_Exceptions $ex) {
         $exs->push($ex);
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }