mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -04:00 
			
		
		
		
	Implement PHP CS Fixer and a coding standard to follow (#471)
* Create PHP CS Fixer config and add to CI workflow * Run php cs fixer on project * Add newline at end of file * Update to use PHP CS Fixer v3 * Run v3 config on project * Run seperate config in CI
This commit is contained in:
		| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Space; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| @ -8,35 +9,35 @@ class DateFormatter | ||||
|     protected static $formats = [ | ||||
|         [ | ||||
|             "carbon_format" => "Y M d", | ||||
|             "moment_format" => "YYYY MMM DD" | ||||
|             "moment_format" => "YYYY MMM DD", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "d M Y", | ||||
|             "moment_format" => "DD MMM YYYY" | ||||
|             "moment_format" => "DD MMM YYYY", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "d/m/Y", | ||||
|             "moment_format" => "DD/MM/YYYY" | ||||
|             "moment_format" => "DD/MM/YYYY", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "d.m.Y", | ||||
|             "moment_format" => "DD.MM.YYYY" | ||||
|             "moment_format" => "DD.MM.YYYY", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "d-m-Y", | ||||
|             "moment_format" => "DD-MM-YYYY" | ||||
|             "moment_format" => "DD-MM-YYYY", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "m/d/Y", | ||||
|             "moment_format" => "MM/DD/YYYY" | ||||
|             "moment_format" => "MM/DD/YYYY", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "Y/m/d", | ||||
|             "moment_format" => " YYYY/MM/DD" | ||||
|             "moment_format" => " YYYY/MM/DD", | ||||
|         ], | ||||
|         [ | ||||
|             "carbon_format" => "Y-m-d", | ||||
|             "moment_format" => "YYYY-MM-DD" | ||||
|             "moment_format" => "YYYY-MM-DD", | ||||
|         ], | ||||
|     ]; | ||||
|  | ||||
| @ -45,11 +46,11 @@ class DateFormatter | ||||
|         $new = []; | ||||
|  | ||||
|         foreach (static::$formats as $format) { | ||||
|             $new[] = array( | ||||
|             $new[] = [ | ||||
|                 "display_date" => Carbon::now()->format($format['carbon_format']) , | ||||
|                 "carbon_format_value" => $format['carbon_format'], | ||||
|                 "moment_format_value" => $format['moment_format'] | ||||
|             ); | ||||
|                 "moment_format_value" => $format['moment_format'], | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         return $new; | ||||
|  | ||||
| @ -2,13 +2,12 @@ | ||||
|  | ||||
| namespace Crater\Space; | ||||
|  | ||||
| use Crater\Http\Requests\DatabaseEnvironmentRequest; | ||||
| use Crater\Http\Requests\DiskEnvironmentRequest; | ||||
| use Crater\Http\Requests\MailEnvironmentRequest; | ||||
| use Exception; | ||||
| use Illuminate\Http\Request; | ||||
| use Crater\Http\Requests\DatabaseEnvironmentRequest; | ||||
| use Crater\Http\Requests\MailEnvironmentRequest; | ||||
| use Crater\Http\Requests\DiskEnvironmentRequest; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Artisan; | ||||
|  | ||||
| class EnvironmentManager | ||||
| { | ||||
| @ -39,8 +38,8 @@ class EnvironmentManager | ||||
|         $newDatabaseData = | ||||
|             'DB_CONNECTION='.$request->database_connection."\n"; | ||||
|  | ||||
|         if($request->has('database_username') && $request->has('database_password')) { | ||||
|             if(env('DB_USERNAME') && env('DB_HOST')){ | ||||
|         if ($request->has('database_username') && $request->has('database_password')) { | ||||
|             if (env('DB_USERNAME') && env('DB_HOST')) { | ||||
|                 $oldDatabaseData = $oldDatabaseData. | ||||
|                     'DB_HOST='.config('database.connections.'.config('database.default').'.host')."\n". | ||||
|                     'DB_PORT='.config('database.connections.'.config('database.default').'.port')."\n". | ||||
| @ -59,8 +58,7 @@ class EnvironmentManager | ||||
|                 'DB_USERNAME='.$request->database_username."\n". | ||||
|                 'DB_PASSWORD="'.$request->database_password."\"\n\n"; | ||||
|         } else { | ||||
|  | ||||
|             if(env('DB_USERNAME') && env('DB_HOST')){ | ||||
|             if (env('DB_USERNAME') && env('DB_HOST')) { | ||||
|                 $oldDatabaseData = $oldDatabaseData. | ||||
|                     'DB_HOST='.config('database.connections.'.config('database.default').'.host')."\n". | ||||
|                     'DB_PORT='.config('database.connections.'.config('database.default').'.port')."\n". | ||||
| @ -77,23 +75,20 @@ class EnvironmentManager | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|  | ||||
|             $this->checkDatabaseConnection($request); | ||||
|  | ||||
|             if(\Schema::hasTable('users') ) { | ||||
|             if (\Schema::hasTable('users')) { | ||||
|                 return [ | ||||
|                     'error' => 'database_should_be_empty' | ||||
|                     'error' => 'database_should_be_empty', | ||||
|                 ]; | ||||
|             } | ||||
|  | ||||
|         } catch (Exception $e) { | ||||
|  | ||||
|             return [ | ||||
|                 'error_message' => $e->getMessage() | ||||
|                 'error_message' => $e->getMessage(), | ||||
|             ]; | ||||
|         } | ||||
|         try { | ||||
|  | ||||
|         try { | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 $oldDatabaseData, | ||||
|                 $newDatabaseData, | ||||
| @ -115,18 +110,17 @@ class EnvironmentManager | ||||
|  | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 'SESSION_DOMAIN='.config('session.domain'), | ||||
|                 'SESSION_DOMAIN='.explode(':',$request->app_domain)[0], | ||||
|                 'SESSION_DOMAIN='.explode(':', $request->app_domain)[0], | ||||
|                 file_get_contents($this->envPath) | ||||
|             )); | ||||
|  | ||||
|         } catch (Exception $e) { | ||||
|             return [ | ||||
|                 'error' => 'database_variables_save_error' | ||||
|                 'error' => 'database_variables_save_error', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'success' => 'database_variables_save_successfully' | ||||
|             'success' => 'database_variables_save_successfully', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| @ -142,16 +136,16 @@ class EnvironmentManager | ||||
|         $settings = config("database.connections.$connection"); | ||||
|  | ||||
|         $connectionArray = array_merge($settings, [ | ||||
|             'driver'   => $connection, | ||||
|             'driver' => $connection, | ||||
|             'database' => $request->database_name, | ||||
|         ]); | ||||
|  | ||||
|         if($request->has('database_username') && $request->has('database_password')) { | ||||
|         if ($request->has('database_username') && $request->has('database_password')) { | ||||
|             $connectionArray = array_merge($connectionArray, [ | ||||
|                 'username' => $request->database_username, | ||||
|                 'password' => $request->database_password, | ||||
|                 'host'     => $request->database_hostname, | ||||
|                 'port'     => $request->database_port, | ||||
|                 'host' => $request->database_hostname, | ||||
|                 'port' => $request->database_port, | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
| @ -166,25 +160,24 @@ class EnvironmentManager | ||||
|         return DB::connection()->getPdo(); | ||||
|     } | ||||
|  | ||||
|      /** | ||||
|      * Save the mail content to the .env file. | ||||
|      * | ||||
|      * @param Request $request | ||||
|      * @return array | ||||
|      */ | ||||
|     /** | ||||
|     * Save the mail content to the .env file. | ||||
|     * | ||||
|     * @param Request $request | ||||
|     * @return array | ||||
|     */ | ||||
|     public function saveMailVariables(MailEnvironmentRequest $request) | ||||
|     { | ||||
|         $mailData = $this->getMailData($request); | ||||
|  | ||||
|         try { | ||||
|  | ||||
|             file_put_contents($this->envPath, str_replace( | ||||
|                 $mailData['old_mail_data'], | ||||
|                 $mailData['new_mail_data'], | ||||
|                 file_get_contents($this->envPath) | ||||
|             )); | ||||
|  | ||||
|             if($mailData['extra_old_mail_data']) { | ||||
|             if ($mailData['extra_old_mail_data']) { | ||||
|                 file_put_contents($this->envPath, str_replace( | ||||
|                     $mailData['extra_old_mail_data'], | ||||
|                     $mailData['extra_mail_data'], | ||||
| @ -197,15 +190,14 @@ class EnvironmentManager | ||||
|                     FILE_APPEND | ||||
|                 ); | ||||
|             } | ||||
|  | ||||
|         } catch (Exception $e) { | ||||
|             return [ | ||||
|                 'error' => 'mail_variables_save_error' | ||||
|                 'error' => 'mail_variables_save_error', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'success' => 'mail_variables_save_successfully' | ||||
|             'success' => 'mail_variables_save_successfully', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| @ -217,7 +209,7 @@ class EnvironmentManager | ||||
|         $oldMailData = ""; | ||||
|         $newMailData = ""; | ||||
|  | ||||
|         if(env('MAIL_FROM_ADDRESS') !== NULL && env('MAIL_FROM_NAME') !== NULL ) { | ||||
|         if (env('MAIL_FROM_ADDRESS') !== null && env('MAIL_FROM_NAME') !== null) { | ||||
|             $mailFromCredential = | ||||
|                 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". | ||||
|                 'MAIL_FROM_NAME="'.config('mail.from.name')."\"\n\n"; | ||||
| @ -267,12 +259,12 @@ class EnvironmentManager | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 $extraMailData= | ||||
|                 $extraMailData = | ||||
|                     'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". | ||||
|                     'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". | ||||
|                     'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n"; | ||||
|  | ||||
|                 if(env('MAILGUN_DOMAIN') !== NULL && env('MAILGUN_SECRET') !== NULL && env('MAILGUN_ENDPOINT') !== NULL) { | ||||
|                 if (env('MAILGUN_DOMAIN') !== null && env('MAILGUN_SECRET') !== null && env('MAILGUN_ENDPOINT') !== null) { | ||||
|                     $extraOldMailData = | ||||
|                         'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". | ||||
|                         'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". | ||||
| @ -301,11 +293,11 @@ class EnvironmentManager | ||||
|                     'MAIL_FROM_ADDRESS='.$request->from_mail."\n". | ||||
|                     'MAIL_FROM_NAME="'.$request->from_name."\"\n\n"; | ||||
|  | ||||
|                 $extraMailData= | ||||
|                 $extraMailData = | ||||
|                     'SES_KEY='.$request->mail_ses_key."\n". | ||||
|                     'SES_SECRET='.$request->mail_ses_secret."\n"; | ||||
|  | ||||
|                 if(env('SES_KEY') !== NULL  && env('SES_SECRET') !== NULL ) { | ||||
|                 if (env('SES_KEY') !== null && env('SES_SECRET') !== null) { | ||||
|                     $extraOldMailData = | ||||
|                         'SES_KEY='.config('services.ses.key')."\n". | ||||
|                         'SES_SECRET='.config('services.ses.secret')."\n"; | ||||
| @ -362,23 +354,22 @@ class EnvironmentManager | ||||
|             'old_mail_data' => $oldMailData, | ||||
|             'new_mail_data' => $newMailData, | ||||
|             'extra_mail_data' => $extraMailData, | ||||
|             'extra_old_mail_data' => $extraOldMailData | ||||
|             'extra_old_mail_data' => $extraOldMailData, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|      /** | ||||
|      * Save the disk content to the .env file. | ||||
|      * | ||||
|      * @param Request $request | ||||
|      * @return array | ||||
|      */ | ||||
|     /** | ||||
|     * Save the disk content to the .env file. | ||||
|     * | ||||
|     * @param Request $request | ||||
|     * @return array | ||||
|     */ | ||||
|     public function saveDiskVariables(DiskEnvironmentRequest $request) | ||||
|     { | ||||
|         $diskData = $this->getDiskData($request); | ||||
|  | ||||
|         try { | ||||
|  | ||||
|             if(!$diskData['old_default_driver']){ | ||||
|             if (! $diskData['old_default_driver']) { | ||||
|                 file_put_contents($this->envPath, $diskData['default_driver'], FILE_APPEND); | ||||
|             } else { | ||||
|                 file_put_contents($this->envPath, str_replace( | ||||
| @ -388,25 +379,23 @@ class EnvironmentManager | ||||
|                 )); | ||||
|             } | ||||
|  | ||||
|             if(!$diskData['old_disk_data']){ | ||||
|             if (! $diskData['old_disk_data']) { | ||||
|                 file_put_contents($this->envPath, $diskData['new_disk_data'], FILE_APPEND); | ||||
|             } else { | ||||
|  | ||||
|                 file_put_contents($this->envPath, str_replace( | ||||
|                     $diskData['old_disk_data'], | ||||
|                     $diskData['new_disk_data'], | ||||
|                     file_get_contents($this->envPath) | ||||
|                 )); | ||||
|             } | ||||
|  | ||||
|         } catch (Exception $e) { | ||||
|             return [ | ||||
|                 'error' => 'disk_variables_save_error' | ||||
|                 'error' => 'disk_variables_save_error', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'success' => 'disk_variables_save_successfully' | ||||
|             'success' => 'disk_variables_save_successfully', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| @ -417,8 +406,8 @@ class EnvironmentManager | ||||
|         $oldDiskData = ""; | ||||
|         $newDiskData = ""; | ||||
|  | ||||
|         if($request->default_driver) { | ||||
|             if(env('FILESYSTEM_DRIVER') !== NULL) { | ||||
|         if ($request->default_driver) { | ||||
|             if (env('FILESYSTEM_DRIVER') !== null) { | ||||
|                 $defaultDriver = "\n".'FILESYSTEM_DRIVER='.$request->default_driver."\n"; | ||||
|  | ||||
|                 $oldDefaultDriver = | ||||
| @ -431,7 +420,7 @@ class EnvironmentManager | ||||
|  | ||||
|         switch ($request->selected_driver) { | ||||
|             case 's3': | ||||
|                 if(env('AWS_KEY') !== NULL){ | ||||
|                 if (env('AWS_KEY') !== null) { | ||||
|                     $oldDiskData = "\n". | ||||
|                         'AWS_KEY='.config('filesystems.disks.s3.key')."\n". | ||||
|                         'AWS_SECRET="'.config('filesystems.disks.s3.secret')."\"\n". | ||||
| @ -450,14 +439,14 @@ class EnvironmentManager | ||||
|                 break; | ||||
|  | ||||
|             case 'doSpaces': | ||||
|                 if(env('DO_SPACES_KEY') !== NULL){ | ||||
|                 if (env('DO_SPACES_KEY') !== null) { | ||||
|                     $oldDiskData = "\n". | ||||
|                         'DO_SPACES_KEY='.config('filesystems.disks.doSpaces.key')."\n". | ||||
|                         'DO_SPACES_SECRET="'.config('filesystems.disks.doSpaces.secret')."\"\n". | ||||
|                         'DO_SPACES_REGION='.config('filesystems.disks.doSpaces.region')."\n". | ||||
|                         'DO_SPACES_BUCKET='.config('filesystems.disks.doSpaces.bucket')."\n". | ||||
|                         'DO_SPACES_ENDPOINT='.config('filesystems.disks.doSpaces.endpoint')."\n"; | ||||
|                         'DO_SPACES_ROOT='.config('filesystems.disks.doSpaces.root')."\n"; | ||||
|                     'DO_SPACES_ROOT='.config('filesystems.disks.doSpaces.root')."\n"; | ||||
|                 } | ||||
|  | ||||
|                 $newDiskData = "\n". | ||||
| @ -471,7 +460,7 @@ class EnvironmentManager | ||||
|                 break; | ||||
|  | ||||
|             case 'dropbox': | ||||
|                 if(env('DROPBOX_TOKEN') !== NULL){ | ||||
|                 if (env('DROPBOX_TOKEN') !== null) { | ||||
|                     $oldDiskData = "\n". | ||||
|                         'DROPBOX_TOKEN='.config('filesystems.disks.dropbox.token')."\n". | ||||
|                         'DROPBOX_KEY='.config('filesystems.disks.dropbox.key')."\n". | ||||
| @ -494,7 +483,7 @@ class EnvironmentManager | ||||
|             'old_disk_data' => $oldDiskData, | ||||
|             'new_disk_data' => $newDiskData, | ||||
|             'default_driver' => $defaultDriver, | ||||
|             'old_default_driver' => $oldDefaultDriver | ||||
|             'old_default_driver' => $oldDefaultDriver, | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -30,7 +30,7 @@ class PermissionsChecker | ||||
|     public function check(array $folders) | ||||
|     { | ||||
|         foreach ($folders as $folder => $permission) { | ||||
|             if (!($this->getPermission($folder) >= $permission)) { | ||||
|             if (! ($this->getPermission($folder) >= $permission)) { | ||||
|                 $this->addFileAndSetErrors($folder, $permission, false); | ||||
|             } else { | ||||
|                 $this->addFile($folder, $permission, true); | ||||
|  | ||||
| @ -34,6 +34,7 @@ class RequirementsChecker | ||||
|                             $results['errors'] = true; | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     break; | ||||
|                 // check apache requirements | ||||
|                 case 'apache': | ||||
| @ -49,6 +50,7 @@ class RequirementsChecker | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -2,25 +2,24 @@ | ||||
|  | ||||
| namespace Crater\Space; | ||||
|  | ||||
| use Crater\Models\Setting; | ||||
| use GuzzleHttp\Client; | ||||
| use GuzzleHttp\Exception\RequestException; | ||||
| use Crater\Models\Setting; | ||||
|  | ||||
| // Implementation taken from Akaunting - https://github.com/akaunting/akaunting | ||||
| trait SiteApi | ||||
| { | ||||
|  | ||||
|     protected static function getRemote($url, $data = array()) | ||||
|     protected static function getRemote($url, $data = []) | ||||
|     { | ||||
|         $base = 'https://craterapp.com/'; | ||||
|  | ||||
|         $client = new Client(['verify' => false, 'base_uri' => $base]); | ||||
|  | ||||
|         $headers['headers'] = array( | ||||
|             'Accept'        => 'application/json', | ||||
|             'Referer'       => url('/'), | ||||
|             'crater'        => Setting::getSetting('version') | ||||
|         ); | ||||
|         $headers['headers'] = [ | ||||
|             'Accept' => 'application/json', | ||||
|             'Referer' => url('/'), | ||||
|             'crater' => Setting::getSetting('version'), | ||||
|         ]; | ||||
|  | ||||
|         $data['http_errors'] = false; | ||||
|  | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Space; | ||||
|  | ||||
| class TimeZones | ||||
|  | ||||
| @ -1,10 +1,11 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Crater\Space; | ||||
|  | ||||
| use File; | ||||
| use Artisan; | ||||
| use GuzzleHttp\Exception\RequestException; | ||||
| use Crater\Events\UpdateFinished; | ||||
| use File; | ||||
| use GuzzleHttp\Exception\RequestException; | ||||
| use ZipArchive; | ||||
|  | ||||
| // Implementation taken from Akaunting - https://github.com/akaunting/akaunting | ||||
| @ -15,11 +16,10 @@ class Updater | ||||
|     public static function checkForUpdate($installed_version) | ||||
|     { | ||||
|         $data = null; | ||||
|         if(env('APP_ENV') === 'development') | ||||
|         { | ||||
|             $url = 'downloads/check/latest/'. $installed_version . '?type=update&is_dev=1'; | ||||
|         if (env('APP_ENV') === 'development') { | ||||
|             $url = 'downloads/check/latest/'.$installed_version.'?type=update&is_dev=1'; | ||||
|         } else { | ||||
|             $url = 'downloads/check/latest/'. $installed_version . '?type=update'; | ||||
|             $url = 'downloads/check/latest/'.$installed_version.'?type=update'; | ||||
|         } | ||||
|  | ||||
|         $response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]); | ||||
| @ -36,7 +36,7 @@ class Updater | ||||
|             foreach (json_decode($extensions) as $extension) { | ||||
|                 $extensionData[$extension] = phpversion($extension) ? true : false; | ||||
|             } | ||||
|             $extensionData['php'. '('.$data->version->minimum_php_version.')'] = version_compare(phpversion(), $data->version->minimum_php_version, ">="); | ||||
|             $extensionData['php'.'('.$data->version->minimum_php_version.')'] = version_compare(phpversion(), $data->version->minimum_php_version, ">="); | ||||
|             $data->version->extensions = $extensionData; | ||||
|         } | ||||
|  | ||||
| @ -49,9 +49,9 @@ class Updater | ||||
|         $path = null; | ||||
|  | ||||
|         if (env('APP_ENV') === 'development') { | ||||
|             $url = 'downloads/file/' . $new_version . '?type=update&is_dev=1&is_cmd='. $is_cmd; | ||||
|             $url = 'downloads/file/'.$new_version.'?type=update&is_dev=1&is_cmd='.$is_cmd; | ||||
|         } else { | ||||
|             $url = 'downloads/file/' . $new_version . '?type=update&is_cmd='. $is_cmd; | ||||
|             $url = 'downloads/file/'.$new_version.'?type=update&is_cmd='.$is_cmd; | ||||
|         } | ||||
|  | ||||
|         $response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]); | ||||
| @ -62,8 +62,8 @@ class Updater | ||||
|                 'success' => false, | ||||
|                 'error' => 'Download Exception', | ||||
|                 'data' => [ | ||||
|                     'path' => $path | ||||
|                 ] | ||||
|                     'path' => $path, | ||||
|                 ], | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
| @ -72,18 +72,18 @@ class Updater | ||||
|         } | ||||
|  | ||||
|         // Create temp directory | ||||
|         $temp_dir = storage_path('app/temp-' . md5(mt_rand())); | ||||
|         $temp_dir = storage_path('app/temp-'.md5(mt_rand())); | ||||
|  | ||||
|         if (!File::isDirectory($temp_dir)) { | ||||
|         if (! File::isDirectory($temp_dir)) { | ||||
|             File::makeDirectory($temp_dir); | ||||
|         } | ||||
|  | ||||
|         $zip_file_path = $temp_dir . '/upload.zip'; | ||||
|         $zip_file_path = $temp_dir.'/upload.zip'; | ||||
|  | ||||
|         // Add content to the Zip file | ||||
|         $uploaded = is_int(file_put_contents($zip_file_path, $data)) ? true : false; | ||||
|  | ||||
|         if (!$uploaded) { | ||||
|         if (! $uploaded) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
| @ -92,13 +92,13 @@ class Updater | ||||
|  | ||||
|     public static function unzip($zip_file_path) | ||||
|     { | ||||
|         if(!file_exists($zip_file_path)) { | ||||
|         if (! file_exists($zip_file_path)) { | ||||
|             throw new \Exception('Zip file not found'); | ||||
|         } | ||||
|  | ||||
|         $temp_extract_dir = storage_path('app/temp2-' . md5(mt_rand())); | ||||
|         $temp_extract_dir = storage_path('app/temp2-'.md5(mt_rand())); | ||||
|  | ||||
|         if (!File::isDirectory($temp_extract_dir)) { | ||||
|         if (! File::isDirectory($temp_extract_dir)) { | ||||
|             File::makeDirectory($temp_extract_dir); | ||||
|         } | ||||
|         // Unzip the file | ||||
| @ -118,7 +118,7 @@ class Updater | ||||
|  | ||||
|     public static function copyFiles($temp_extract_dir) | ||||
|     { | ||||
|         if (!File::copyDirectory($temp_extract_dir . '/Crater', base_path())) { | ||||
|         if (! File::copyDirectory($temp_extract_dir.'/Crater', base_path())) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
| @ -132,7 +132,7 @@ class Updater | ||||
|     { | ||||
|         $files = json_decode($json); | ||||
|  | ||||
|         foreach($files as $file) { | ||||
|         foreach ($files as $file) { | ||||
|             \File::delete(base_path($file)); | ||||
|         } | ||||
|  | ||||
| @ -153,7 +153,7 @@ class Updater | ||||
|         return [ | ||||
|             'success' => true, | ||||
|             'error' => false, | ||||
|             'data' => [] | ||||
|             'data' => [], | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| use Crater\Models\CompanySetting; | ||||
| use Crater\Models\Currency; | ||||
| use Crater\Models\CustomField; | ||||
| @ -11,10 +12,9 @@ use Illuminate\Support\Str; | ||||
|  * @param string $active | ||||
|  * @return string | ||||
|  */ | ||||
| function set_active($path, $active = 'active') { | ||||
|  | ||||
| function set_active($path, $active = 'active') | ||||
| { | ||||
|     return call_user_func_array('Request::is', (array)$path) ? $active : ''; | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
| @ -76,7 +76,7 @@ function format_money_pdf($money, $currency = null) | ||||
| { | ||||
|     $money = $money / 100; | ||||
|  | ||||
|     if (!$currency) { | ||||
|     if (! $currency) { | ||||
|         $currency = Currency::findOrFail(CompanySetting::getSetting('currency', 1)); | ||||
|     } | ||||
|  | ||||
| @ -93,6 +93,7 @@ function format_money_pdf($money, $currency = null) | ||||
|     } else { | ||||
|         $currency_with_symbol = '<span style="font-family: DejaVu Sans;">'.$currency->symbol.'</span>'.$format_money; | ||||
|     } | ||||
|  | ||||
|     return $currency_with_symbol; | ||||
| } | ||||
|  | ||||
| @ -110,14 +111,14 @@ function clean_slug($model, $title, $id = 0) | ||||
|     $allSlugs = getRelatedSlugs($model, $slug, $id); | ||||
|  | ||||
|     // If we haven't used it before then we are all good. | ||||
|     if (!$allSlugs->contains('slug', $slug)) { | ||||
|     if (! $allSlugs->contains('slug', $slug)) { | ||||
|         return $slug; | ||||
|     } | ||||
|  | ||||
|     // Just append numbers like a savage until we find not used. | ||||
|     for ($i = 1; $i <= 10; $i++) { | ||||
|         $newSlug = $slug . '_' . $i; | ||||
|         if (!$allSlugs->contains('slug', $newSlug)) { | ||||
|         $newSlug = $slug.'_'.$i; | ||||
|         if (! $allSlugs->contains('slug', $newSlug)) { | ||||
|             return $newSlug; | ||||
|         } | ||||
|     } | ||||
| @ -127,7 +128,7 @@ function clean_slug($model, $title, $id = 0) | ||||
|  | ||||
| function getRelatedSlugs($type, $slug, $id = 0) | ||||
| { | ||||
|     return CustomField::select('slug')->where('slug', 'like', $slug . '%') | ||||
|     return CustomField::select('slug')->where('slug', 'like', $slug.'%') | ||||
|         ->where('model_type', $type) | ||||
|         ->where('id', '<>', $id) | ||||
|         ->get(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user