mirror of
https://github.com/crater-invoice/crater.git
synced 2025-11-01 06:01:08 -04:00
build version 400
This commit is contained in:
@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@ -25,7 +26,7 @@ class EnvironmentManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the form content to the .env file.
|
||||
* Save the database content to the .env file.
|
||||
*
|
||||
* @param DatabaseEnvironmentRequest $request
|
||||
* @return array
|
||||
@ -33,20 +34,47 @@ class EnvironmentManager
|
||||
public function saveDatabaseVariables(DatabaseEnvironmentRequest $request)
|
||||
{
|
||||
$oldDatabaseData =
|
||||
'DB_CONNECTION='.config('database.default')."\n".
|
||||
'DB_HOST='.config('database.connections.'.config('database.default').'.host')."\n".
|
||||
'DB_PORT='.config('database.connections.'.config('database.default').'.port')."\n".
|
||||
'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n".
|
||||
'DB_USERNAME='.config('database.connections.'.config('database.default').'.username')."\n".
|
||||
'DB_PASSWORD="'.config('database.connections.'.config('database.default').'.password')."\"\n\n";
|
||||
'DB_CONNECTION='.config('database.default')."\n";
|
||||
|
||||
$newDatabaseData =
|
||||
'DB_CONNECTION='.$request->database_connection."\n".
|
||||
'DB_HOST='.$request->database_hostname."\n".
|
||||
'DB_PORT='.$request->database_port."\n".
|
||||
'DB_DATABASE='.$request->database_name."\n".
|
||||
'DB_USERNAME='.$request->database_username."\n".
|
||||
'DB_PASSWORD="'.$request->database_password."\"\n\n";
|
||||
'DB_CONNECTION='.$request->database_connection."\n";
|
||||
|
||||
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".
|
||||
'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n".
|
||||
'DB_USERNAME='.config('database.connections.'.config('database.default').'.username')."\n".
|
||||
'DB_PASSWORD="'.config('database.connections.'.config('database.default').'.password')."\"\n\n";
|
||||
} else {
|
||||
$oldDatabaseData = $oldDatabaseData.
|
||||
'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n\n";
|
||||
}
|
||||
|
||||
$newDatabaseData = $newDatabaseData.
|
||||
'DB_HOST='.$request->database_hostname."\n".
|
||||
'DB_PORT='.$request->database_port."\n".
|
||||
'DB_DATABASE='.$request->database_name."\n".
|
||||
'DB_USERNAME='.$request->database_username."\n".
|
||||
'DB_PASSWORD="'.$request->database_password."\"\n\n";
|
||||
} else {
|
||||
|
||||
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".
|
||||
'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n".
|
||||
'DB_USERNAME='.config('database.connections.'.config('database.default').'.username')."\n".
|
||||
'DB_PASSWORD="'.config('database.connections.'.config('database.default').'.password')."\"\n\n";
|
||||
} else {
|
||||
$oldDatabaseData = $oldDatabaseData.
|
||||
'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n\n";
|
||||
}
|
||||
|
||||
$newDatabaseData = $newDatabaseData.
|
||||
'DB_DATABASE='.$request->database_name."\n\n";
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -64,7 +92,6 @@ class EnvironmentManager
|
||||
'error_message' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
file_put_contents($this->envPath, str_replace(
|
||||
@ -79,6 +106,19 @@ class EnvironmentManager
|
||||
file_get_contents($this->envPath)
|
||||
));
|
||||
|
||||
file_put_contents($this->envPath, str_replace(
|
||||
'SANCTUM_STATEFUL_DOMAINS='.env('SANCTUM_STATEFUL_DOMAINS'),
|
||||
'SANCTUM_STATEFUL_DOMAINS='.$request->app_domain,
|
||||
file_get_contents($this->envPath)
|
||||
));
|
||||
|
||||
|
||||
file_put_contents($this->envPath, str_replace(
|
||||
'SESSION_DOMAIN='.config('session.domain'),
|
||||
'SESSION_DOMAIN='.explode(':',$request->app_domain)[0],
|
||||
file_get_contents($this->envPath)
|
||||
));
|
||||
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'error' => 'database_variables_save_error'
|
||||
@ -91,7 +131,43 @@ class EnvironmentManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the form content to the .env file.
|
||||
*
|
||||
* @param DatabaseEnvironmentRequest $request
|
||||
* @return bool
|
||||
*/
|
||||
private function checkDatabaseConnection(DatabaseEnvironmentRequest $request)
|
||||
{
|
||||
$connection = $request->database_connection;
|
||||
|
||||
$settings = config("database.connections.$connection");
|
||||
|
||||
$connectionArray = array_merge($settings, [
|
||||
'driver' => $connection,
|
||||
'database' => $request->database_name,
|
||||
]);
|
||||
|
||||
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,
|
||||
]);
|
||||
}
|
||||
|
||||
config([
|
||||
'database' => [
|
||||
'migrations' => 'migrations',
|
||||
'default' => $connection,
|
||||
'connections' => [$connection => $connectionArray],
|
||||
],
|
||||
]);
|
||||
|
||||
return DB::connection()->getPdo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the mail content to the .env file.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
@ -290,34 +366,135 @@ class EnvironmentManager
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Save the disk content to the .env file.
|
||||
*
|
||||
* @param DatabaseEnvironmentRequest $request
|
||||
* @return bool
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
private function checkDatabaseConnection(DatabaseEnvironmentRequest $request)
|
||||
public function saveDiskVariables(DiskEnvironmentRequest $request)
|
||||
{
|
||||
$connection = $request->database_connection;
|
||||
$diskData = $this->getDiskData($request);
|
||||
|
||||
$settings = config("database.connections.$connection");
|
||||
try {
|
||||
|
||||
config([
|
||||
'database' => [
|
||||
'migrations' => 'migrations',
|
||||
'default' => $connection,
|
||||
'connections' => [
|
||||
$connection => array_merge($settings, [
|
||||
'driver' => $connection,
|
||||
'host' => $request->database_hostname,
|
||||
'port' => $request->database_port,
|
||||
'database' => $request->database_name,
|
||||
'username' => $request->database_username,
|
||||
'password' => $request->database_password,
|
||||
]),
|
||||
],
|
||||
],
|
||||
]);
|
||||
if(!$diskData['old_default_driver']){
|
||||
file_put_contents($this->envPath, $diskData['default_driver'], FILE_APPEND);
|
||||
} else {
|
||||
file_put_contents($this->envPath, str_replace(
|
||||
$diskData['old_default_driver'],
|
||||
$diskData['default_driver'],
|
||||
file_get_contents($this->envPath)
|
||||
));
|
||||
}
|
||||
|
||||
return DB::connection()->getPdo();
|
||||
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'
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => 'disk_variables_save_successfully'
|
||||
];
|
||||
}
|
||||
|
||||
private function getDiskData($request)
|
||||
{
|
||||
$oldDefaultDriver = "";
|
||||
$defaultDriver = "";
|
||||
$oldDiskData = "";
|
||||
$newDiskData = "";
|
||||
|
||||
if($request->default_driver) {
|
||||
if(env('FILESYSTEM_DRIVER') !== NULL) {
|
||||
$defaultDriver = "\n".'FILESYSTEM_DRIVER='.$request->default_driver."\n";
|
||||
|
||||
$oldDefaultDriver =
|
||||
"\n".'FILESYSTEM_DRIVER='.config('filesystems.default')."\n";
|
||||
} else {
|
||||
$defaultDriver =
|
||||
"\n".'FILESYSTEM_DRIVER='.$request->default_driver."\n";
|
||||
}
|
||||
}
|
||||
|
||||
switch ($request->selected_driver) {
|
||||
case 's3':
|
||||
if(env('AWS_KEY') !== NULL){
|
||||
$oldDiskData = "\n".
|
||||
'AWS_KEY='.config('filesystems.disks.s3.key')."\n".
|
||||
'AWS_SECRET="'.config('filesystems.disks.s3.secret')."\"\n".
|
||||
'AWS_REGION='.config('filesystems.disks.s3.region')."\n".
|
||||
'AWS_BUCKET='.config('filesystems.disks.s3.bucket')."\n".
|
||||
'AWS_ROOT='.config('filesystems.disks.s3.root')."\n";
|
||||
}
|
||||
|
||||
$newDiskData = "\n".
|
||||
'AWS_KEY='.$request->aws_key."\n".
|
||||
'AWS_SECRET="'.$request->aws_secret."\"\n".
|
||||
'AWS_REGION='.$request->aws_region."\n".
|
||||
'AWS_BUCKET='.$request->aws_bucket."\n".
|
||||
'AWS_ROOT='.$request->aws_root."\n";
|
||||
|
||||
break;
|
||||
|
||||
case 'doSpaces':
|
||||
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";
|
||||
}
|
||||
|
||||
$newDiskData = "\n".
|
||||
'DO_SPACES_KEY='.$request->do_spaces_key."\n".
|
||||
'DO_SPACES_SECRET="'.$request->do_spaces_secret."\"\n".
|
||||
'DO_SPACES_REGION='.$request->do_spaces_region."\n".
|
||||
'DO_SPACES_BUCKET='.$request->do_spaces_bucket."\n".
|
||||
'DO_SPACES_ENDPOINT='.$request->do_spaces_endpoint."\n";
|
||||
'DO_SPACES_ROOT='.$request->do_spaces_root."\n\n";
|
||||
|
||||
break;
|
||||
|
||||
case 'dropbox':
|
||||
if(env('DROPBOX_TOKEN') !== NULL){
|
||||
$oldDiskData = "\n".
|
||||
'DROPBOX_TOKEN='.config('filesystems.disks.dropbox.token')."\n".
|
||||
'DROPBOX_KEY='.config('filesystems.disks.dropbox.key')."\n".
|
||||
'DROPBOX_SECRET="'.config('filesystems.disks.dropbox.secret')."\"\n".
|
||||
'DROPBOX_APP='.config('filesystems.disks.dropbox.app')."\n".
|
||||
'DROPBOX_ROOT='.config('filesystems.disks.dropbox.root')."\n";
|
||||
}
|
||||
|
||||
$newDiskData = "\n".
|
||||
'DROPBOX_TOKEN='.$request->dropbox_token."\n".
|
||||
'DROPBOX_KEY='.$request->dropbox_key."\n".
|
||||
'DROPBOX_SECRET="'.$request->dropbox_secret."\"\n".
|
||||
'DROPBOX_APP='.$request->dropbox_app."\n".
|
||||
'DROPBOX_ROOT='.$request->dropbox_root."\n";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'old_disk_data' => $oldDiskData,
|
||||
'new_disk_data' => $newDiskData,
|
||||
'default_driver' => $defaultDriver,
|
||||
'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);
|
||||
|
||||
@ -4,7 +4,7 @@ namespace Crater\Space;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Crater\Setting;
|
||||
use Crater\Models\Setting;
|
||||
|
||||
// Implementation taken from Akaunting - https://github.com/akaunting/akaunting
|
||||
trait SiteApi
|
||||
|
||||
@ -43,15 +43,15 @@ class Updater
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function download($new_version)
|
||||
public static function download($new_version, $is_cmd = 0)
|
||||
{
|
||||
$data = null;
|
||||
$path = null;
|
||||
|
||||
if (env('APP_ENV') === 'development') {
|
||||
$url = 'downloads/file/' . $new_version . '?type=update&is_dev=1';
|
||||
$url = 'downloads/file/' . $new_version . '?type=update&is_dev=1&is_cmd='. $is_cmd;
|
||||
} else {
|
||||
$url = 'downloads/file/' . $new_version . '?type=update';
|
||||
$url = 'downloads/file/' . $new_version . '?type=update&is_cmd='. $is_cmd;
|
||||
}
|
||||
|
||||
$response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]);
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
use Crater\CompanySetting;
|
||||
use Crater\Currency;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\CustomField;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Set Active Path
|
||||
@ -25,16 +27,45 @@ function is_url($path)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
function clean_slug($string)
|
||||
function getCustomFieldValueKey(string $type)
|
||||
{
|
||||
// Replaces all spaces with hyphens.
|
||||
$string = str_replace(' ', '-', $string);
|
||||
switch ($type) {
|
||||
case 'Input':
|
||||
return 'string_answer';
|
||||
|
||||
// Removes special chars.
|
||||
return \Illuminate\Support\Str::lower(preg_replace('/[^A-Za-z0-9\-]/', '', $string));
|
||||
case 'TextArea':
|
||||
return 'string_answer';
|
||||
|
||||
case 'Phone':
|
||||
return 'number_answer';
|
||||
|
||||
case 'Url':
|
||||
return 'string_answer';
|
||||
|
||||
case 'Number':
|
||||
return 'number_answer';
|
||||
|
||||
case 'Dropdown':
|
||||
return 'string_answer';
|
||||
|
||||
case 'Switch':
|
||||
return 'boolean_answer';
|
||||
|
||||
case 'Date':
|
||||
return 'date_answer';
|
||||
|
||||
case 'Time':
|
||||
return 'time_answer';
|
||||
|
||||
case 'DateTime':
|
||||
return 'date_time_answer';
|
||||
|
||||
default:
|
||||
return 'string_answer';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,3 +95,40 @@ function format_money_pdf($money, $currency = null)
|
||||
}
|
||||
return $currency_with_symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @return string
|
||||
*/
|
||||
function clean_slug($model, $title, $id = 0)
|
||||
{
|
||||
// Normalize the title
|
||||
$slug = Str::upper('CUSTOM_'.$model.'_'.Str::slug($title, '_'));
|
||||
|
||||
// Get any that could possibly be related.
|
||||
// This cuts the queries down by doing it once.
|
||||
$allSlugs = getRelatedSlugs($model, $slug, $id);
|
||||
|
||||
// If we haven't used it before then we are all good.
|
||||
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)) {
|
||||
return $newSlug;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \Exception('Can not create a unique slug');
|
||||
}
|
||||
|
||||
function getRelatedSlugs($type, $slug, $id = 0)
|
||||
{
|
||||
return CustomField::select('slug')->where('slug', 'like', $slug . '%')
|
||||
->where('model_type', $type)
|
||||
->where('id', '<>', $id)
|
||||
->get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user