/**
  * Performs any clean-up logic when we know the job is completed.
  * In this case, we delete the temporary file
  * @param JobParameters $job_parameters
  * @return boolean
  */
 public function cleanup_job(JobParameters $job_parameters)
 {
     $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), true, 'd');
     return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
 }
Ejemplo n.º 2
0
 /**
  * write_file
  * @param string $full_file_path
  * @param string $file_contents - the content to be written to the file
  * @param string $file_type
  * @throws EE_Error
  * @return bool
  */
 public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '')
 {
     $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
     $file_type = !empty($file_type) ? rtrim($file_type, ' ') . ' ' : '';
     $folder = EEH_File::remove_filename_from_filepath($full_file_path);
     if (!EEH_File::verify_is_writable($folder, 'folder')) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     // load WP_Filesystem and set file permissions
     $wp_filesystem = EEH_File::_get_wp_filesystem();
     // write the file
     if (!$wp_filesystem->put_contents($full_file_path, $file_contents)) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     return TRUE;
 }
 public function test_remove_filename_form_filepath()
 {
     $file_path = '/var/whatever/thing.txt';
     $this->assertEquals('/var/whatever', EEH_File::remove_filename_from_filepath($file_path));
 }
Ejemplo n.º 4
0
 /**
  * Copies a file. Mostly a wrapper of WP_Filesystem::copy
  * @param string $source_file
  * @param string $destination_file
  * @param boolean $overwrite
  * @throws EE_Error if filesystem credentials are required
  * @return boolean success
  */
 public static function copy($source_file, $destination_file, $overwrite = FALSE)
 {
     $full_source_path = EEH_File::standardise_directory_separators($source_file);
     if (!EEH_File::exists($full_source_path)) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     $full_dest_path = EEH_File::standardise_directory_separators($destination_file);
     $folder = EEH_File::remove_filename_from_filepath($full_dest_path);
     if (!EEH_File::verify_is_writable($folder, 'folder')) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     // load WP_Filesystem and set file permissions
     $wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
     // write the file
     if (!$wp_filesystem->copy(EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), $overwrite)) {
         if (defined('WP_DEBUG') && WP_DEBUG) {
             $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
             $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
             throw new EE_Error($msg);
         }
         return FALSE;
     }
     return TRUE;
 }