Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
lanhktc committed Oct 13, 2019
1 parent cb97c00 commit 920ac2c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 148 deletions.
14 changes: 7 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=sc_api_key
APP_DEBUG=false
APP_URL=your_domain
APP_URL=sc_your_domain

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=database_host
DB_PORT=database_port
DB_DATABASE=database_name
DB_USERNAME=database_user
DB_PASSWORD=database_password
DB_HOST=sc_database_host
DB_PORT=sc_database_port
DB_DATABASE=sc_database_name
DB_USERNAME=sc_database_user
DB_PASSWORD=sc_database_password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down
2 changes: 1 addition & 1 deletion app/Library/Helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function sc_config($key = null, $default = null)
if (!function_exists('sc_store')) {
function sc_store($key = null, $default = null)
{
$allStoreInfo = AdminStore::getData()->toArray();
$allStoreInfo = AdminStore::getData();
$lang = app()->getLocale();
$descriptions = $allStoreInfo['descriptions'];
foreach ($descriptions as $row) {
Expand Down
2 changes: 1 addition & 1 deletion config/scart.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
return [
'version' => '3.0.4.1',
'version' => '3.0.4.2',
'homepage' => 'https://s-cart.org',
'name' => 'S-Cart',
'title' => 'Free Open Source eCommerce for Business',
Expand Down
158 changes: 65 additions & 93 deletions public/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/

require __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
$app = include_once __DIR__ . '/../bootstrap/app.php';
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Artisan;

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
Expand All @@ -19,115 +20,86 @@
$step = request('step');
switch ($step) {
case 'step1':
$domain = request()->getSchemeAndHttpHost();
$database_host = request('database_host') ?? '127.0.0.1';
$database_port = request('database_port') ?? '3306';
$database_name = request('database_name') ?? '';
$database_user = request('database_user') ?? '';
$domain = request()->getSchemeAndHttpHost();
$database_host = request('database_host') ?? '127.0.0.1';
$database_port = request('database_port') ?? '3306';
$database_name = request('database_name') ?? '';
$database_user = request('database_user') ?? '';
$database_password = request('database_password') ?? '';
$admin_url = request('admin_url') ?? '';
try {
$getEnv = file_get_contents(base_path() . '/.env.example');
$getEnv = str_replace('your_domain', $domain, $getEnv);
$getEnv = str_replace('database_host', $database_host, $getEnv);
$getEnv = str_replace('database_port', $database_port, $getEnv);
$getEnv = str_replace('database_name', $database_name, $getEnv);
$getEnv = str_replace('database_user', $database_user, $getEnv);
$getEnv = str_replace('database_password', $database_password, $getEnv);
if ($admin_url) {
$getEnv = str_replace('sc_admin', $admin_url, $getEnv);
}
$env = fopen(base_path() . "/.env", "w") or die(json_encode(['error' => 1, 'msg' => trans('install.env.error_open')]));
fwrite($env, $getEnv);
fclose($env);
Artisan::call('route:clear');
Artisan::call('config:clear');
Artisan::call('cache:clear');
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
exit();
}
echo json_encode(['error' => 0, 'msg' => trans('install.env.process_sucess')]);
break;
$admin_url = request('admin_url') ?? '';
try {
$api_key = 'base64:' . base64_encode(
Encrypter::generateKey(config('app.cipher'))
);
$getEnv = file_get_contents(base_path() . '/.env.example');
$getEnv = str_replace('sc_your_domain', $domain, $getEnv);
$getEnv = str_replace('sc_database_host', $database_host, $getEnv);
$getEnv = str_replace('sc_database_port', $database_port, $getEnv);
$getEnv = str_replace('sc_database_name', $database_name, $getEnv);
$getEnv = str_replace('sc_database_user', $database_user, $getEnv);
$getEnv = str_replace('sc_database_password', $database_password, $getEnv);
$getEnv = str_replace('sc_api_key', $api_key, $getEnv);

case 'step2':
try {
Artisan::call('key:generate');
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
exit;
if ($admin_url) {
$getEnv = str_replace('sc_admin', $admin_url, $getEnv);
}
echo json_encode(['error' => 0, 'msg' => trans('install.key.process_sucess')]);
break;
$env = fopen(base_path() . "/.env", "w") or die(json_encode(['error' => 1, 'msg' => trans('install.env.error_open')]));
fwrite($env, $getEnv);
fclose($env);

case 'step3':

try {
\Illuminate\Support\Facades\DB::connection()->getPdo();
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
break;
}
Artisan::call('migrate --force');
echo json_encode(['error' => 0, 'msg' => trans('install.database.process_sucess')]);
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
exit();
}
echo json_encode(['error' => 0, 'msg' => trans('install.env.process_sucess')]);
break;

case 'step4':
try {
foldes_permissions();
try {
rename(base_path() . '/public/install.php', base_path() . '/public/install.scart');
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => trans('install.rename_error')]);
exit();
}

} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
exit();
case 'step2':
Artisan::call('migrate --force');
try {
\Illuminate\Support\Facades\DB::connection()->getPdo();
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => $e->getMessage()]);
break;
}

}
echo json_encode(['error' => 0, 'msg' => trans('install.database.process_sucess')]);
break;

Artisan::call('route:clear');
Artisan::call('config:clear');
Artisan::call('cache:clear');
echo json_encode(['error' => 0, 'msg' => trans('install.permission.process_sucess')]);
break;
case 'step3':
try {
rename(base_path() . '/public/install.php', base_path() . '/public/install.scart');
} catch (\Exception $e) {
echo json_encode(['error' => 1, 'msg' => trans('install.rename_error')]);
exit();
}
echo json_encode(['error' => 0]);
break;

default:
# code...
break;
default:
break;
}
} else {

$requirements = [
'PHP >= 7.1.3' => version_compare(PHP_VERSION, '7.1.3', '>='),
'BCMath PHP Extension' => extension_loaded('bcmath'),
'Ctype PHP Extension' => extension_loaded('ctype'),
'JSON PHP Extension' => extension_loaded('json'),
'OpenSSL PHP Extension' => extension_loaded('openssl'),
'PDO PHP Extension' => extension_loaded('pdo'),
'Tokenizer PHP Extension' => extension_loaded('tokenizer'),
'XML PHP extension' => extension_loaded('xml'),
'xmlwriter PHP extension' => extension_loaded('xmlwriter'),
'Mbstring PHP extension' => extension_loaded('mbstring'),
'ZipArchive PHP extension' => extension_loaded('zip'),
'GD (optional) PHP extension' => extension_loaded('gd'),
'PHP >= 7.1.3' => version_compare(PHP_VERSION, '7.1.3', '>='),
'BCMath PHP Extension' => extension_loaded('bcmath'),
'Ctype PHP Extension' => extension_loaded('ctype'),
'JSON PHP Extension' => extension_loaded('json'),
'OpenSSL PHP Extension' => extension_loaded('openssl'),
'PDO PHP Extension' => extension_loaded('pdo'),
'Tokenizer PHP Extension' => extension_loaded('tokenizer'),
'XML PHP extension' => extension_loaded('xml'),
'xmlwriter PHP extension' => extension_loaded('xmlwriter'),
'Mbstring PHP extension' => extension_loaded('mbstring'),
'ZipArchive PHP extension' => extension_loaded('zip'),
'GD (optional) PHP extension' => extension_loaded('gd'),
'Dom (optional) PHP extension' => extension_loaded('dom'),
];

echo view('install', array(
'path_lang' => (($lang != 'en') ? "?lang=" . $lang : ""),
'title' => trans('install.title'), 'requirements' => $requirements)
'title' => trans('install.title'), 'requirements' => $requirements)
);
exit();
}

function foldes_permissions()
{
$foldes = array(
base_path() . '/vendor/',
public_path() . '/data/',
);
exec('chmod o+w -R ' . implode(' ', $foldes));
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ Step6:
- Font-end : http://demo.s-cart.org
- Back-end: http://demo.s-cart.org/sc_admin <code>User/pass: test/123456</code>

###

VPS SSD $5/mo, gets $50 in credit over 30 days. [DigitalOcean](https://m.do.co/c/450877e92a78).
6 changes: 6 additions & 0 deletions resources/lang/en/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
'process_sucess' => 'Setting permission success!',
'error' => 'Error while initializing setting permission folder',
],
'complete' => [
'process' => 'Prepare to finish',
'process_sucess' => 'Completed!',
'error' => 'Error while finish',
],

'validate' => [
'database_port_number' => 'Database port is number',
'database_port_required' => 'Database port required',
Expand Down
6 changes: 6 additions & 0 deletions resources/lang/vi/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
'process_sucess' => 'Thiết lập quyền thành công!',
'error' => 'Lỗi trong khi thiết lập quyền các thư mục',
],
'complete' => [
'process' => 'Chuẩn bị để kết thúc',
'process_sucess' => 'Hoàn tất!',
'error' => 'Có lỗi trong khi kết thúc công việc',
],

'validate' => [
'database_port_number' => 'Port của dữ liệu là số',
'database_port_required' => 'Port dữ liệu là bắt buộc',
Expand Down
55 changes: 9 additions & 46 deletions resources/views/install.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
$('#msg').html(data.msg);
$('.progress-bar').css("width","25%");
$('.progress-bar').html("25%");
setTimeout(generateKey, 1000);
setTimeout(installDatabase, 1000);
}else{
$('#msg').removeClass('success');
$('#msg').addClass('error');
Expand All @@ -187,49 +187,11 @@
$('#msg').removeClass('success');
$('#msg').addClass('error');
$('#msg').html('{{ trans('install.env.error') }}');
})
}
});
function generateKey(){
$('#msg').removeClass('error');
$('#msg').removeClass('success');
$('#msg').html('{{ trans('install.key.process') }}');
$.ajax({
url: 'install.php{{ $path_lang }}',
type: 'POST',
dataType: 'json',
data: {step: 'step2'},
})
.done(function(data) {
$('#msg').removeClass('success');
$('#msg').removeClass('error');
error = parseInt(data.error);
if(error != 1 && error !=0){
$('#msg').addClass('error');
$('#msg').html(data);
}
else if(error ===0)
{
$('#msg').addClass('success');
$('#msg').html(data.msg);
$('.progress-bar').css("width","50%");
$('.progress-bar').html("50%");
setTimeout(installDatabase, 2000);
}else{
$('#msg').addClass('error');
$('#msg').html(data.msg);
}
})
.fail(function() {
$('#msg').removeClass('success');
$('#msg').addClass('error');
$('#msg').html('{{ trans('install.key.error') }}');
})
}
function installDatabase(){
$('#msg').removeClass('error');
$('#msg').removeClass('success');
Expand All @@ -238,7 +200,7 @@ function installDatabase(){
url: 'install.php{{ $path_lang }}',
type: 'POST',
dataType: 'json',
data: {step: 'step3'},
data: {step: 'step2'},
})
.done(function(data) {
Expand All @@ -255,7 +217,7 @@ function installDatabase(){
$('#msg').html(data.msg);
$('.progress-bar').css("width","75%");
$('.progress-bar').html("75%");
setTimeout(setPermission, 2000);
setTimeout(completeInstall, 2000);
}else{
$('#msg').addClass('error');
$('#msg').html(data.msg);
Expand All @@ -269,15 +231,15 @@ function installDatabase(){
})
}
function setPermission(){
function completeInstall(){
$('#msg').removeClass('error');
$('#msg').removeClass('success');
$('#msg').html('{{ trans('install.permission.process') }}');
$('#msg').html('{{ trans('install.complete.process') }}');
$.ajax({
url: 'install.php{{ $path_lang }}',
type: 'POST',
dataType: 'json',
data: {step: 'step4'},
data: {step: 'step3'},
})
.done(function(data) {
Expand All @@ -294,6 +256,7 @@ function setPermission(){
$('#msg').html(data.msg);
$('.progress-bar').css("width","100%");
$('.progress-bar').html("100%");
$('#msg').html('{{ trans('install.complete.process_success') }}');
setTimeout(function(){ window.location.replace($('#admin_url').val()); }, 2000);
}else{
$('#msg').addClass('error');
Expand All @@ -303,7 +266,7 @@ function setPermission(){
.fail(function() {
$('#msg').removeClass('success');
$('#msg').addClass('error');
$('#msg').html('{{ trans('install.permission.error') }}');
$('#msg').html('{{ trans('install.complete.error') }}');
})
}
Expand Down

0 comments on commit 920ac2c

Please sign in to comment.