Skip to content

Commit

Permalink
Add rewriteConfig() and invoke twice incase unexpect failure
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStack committed Jan 31, 2021
1 parent be6cd43 commit e083bdf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ composer require alexstack/laravel-cms && php artisan laravelcms

```php
// Step 1: Install Laravel to folder cms
composer create-project --prefer-dist laravel/laravel cms && cd cms && composer require alexstack/laravel-cms
composer create-project laravel/laravel cms && cd cms && composer require alexstack/laravel-cms

// Step 2: Change the database connection settings in the .env
cd cms & vi .env
vi .env // change DB_DATABASE, DB_USERNAME, DB_PASSWORD

// Step 3: install cms
php artisan laravelcms
// Step 3: install CMS
php artisan laravelcms  --silent=yes

// Step 4: Enable Laravel auth/login system
composer require laravel/ui && php artisan ui bootstrap --auth && php artisan migrate
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "alexstack/laravel-cms",
"description": "Simple Bootstrap Laravel CMS. Can integrate to any existing Laravel project. Only add few database tables with prefix, not effect your existing database tables. Support Laravel 7.x & Laravel 6.x & Laravel 5.x - Amila Laravel CMS",
"description": "Simple Bootstrap Laravel CMS. Can integrate to any existing Laravel project. Only add few database tables with prefix, not effect your existing database tables. Support Laravel 8.x & 7.x & Laravel 6.x & Laravel 5.x - Amila Laravel CMS",
"type": "library",
"homepage": "https://github.com/AlexStack/Laravel-CMS/",
"keywords": ["laravel", "laravel cms", "laravel blog", "laravel wordpress", "LaravelCMS", "amila laravel cms", "php cms", "cms", "laravel 6", "laravel6", "laravel 7", "laravel7", "Amila CMS", "headless cms", "existing laravel project"],
"keywords": ["laravel", "laravel cms", "laravel blog", "laravel wordpress", "LaravelCMS", "amila laravel cms", "php cms", "cms", "laravel 6", "laravel6", "laravel 7", "laravel7", "Amila CMS", "headless cms", "existing laravel project", "laravel 8"],
"license": "MIT",
"support": {
"issues": "https://github.com/AlexStack/Laravel-CMS/issues"
Expand Down
36 changes: 26 additions & 10 deletions src/Console/Commands/LaravelCMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,17 @@ public function initializeCms($options)
'--provider' => 'AlexStack\LaravelCms\LaravelCmsServiceProvider',
]);

if ('cms_' != $table_prefix || 'en' != $app_locale) {
$config_str = str_replace(
["=> 'cms_", "=> 'en"],
["=> '".$table_prefix, "=> '".$app_locale],
file_get_contents(dirname(__FILE__, 3).'/config/laravel-cms.php')
);
$config_str = trim($config_str); // in case it not change in ram memory
file_put_contents(base_path('config/laravel-cms.php'), $config_str);
$this->line('<fg=cyan>----> Changed db table prefix to : </><fg=yellow>'.$table_prefix.'</>');
}
// if ('cms_' != $table_prefix || 'en' != $app_locale) {
// $config_str = str_replace(
// ["=> 'cms_", "=> 'en"],
// ["=> '".$table_prefix, "=> '".$app_locale],
// file_get_contents(dirname(__FILE__, 3).'/config/laravel-cms.php')
// );
// $config_str = trim($config_str); // in case it not change in ram memory
// file_put_contents(base_path('config/laravel-cms.php'), $config_str);
// $this->line('<fg=cyan>----> Changed db table prefix to : </><fg=yellow>'.$table_prefix.'</>');
// }
$this->rewriteConfig($table_prefix, $app_locale);

$this->call('config:cache');
$this->call('route:clear');
Expand Down Expand Up @@ -371,6 +372,8 @@ public function initializeCms($options)

$this->forBrandNewProject();

$this->rewriteConfig($table_prefix, $app_locale); // incase something wrong

$this->clearCache($options);

// success message
Expand Down Expand Up @@ -466,4 +469,17 @@ public function forBrandNewProject(){
$this->copyCmsFiles($source_files, $target_dir, $backup_dir, $ignore_files);
}
}

public function rewriteConfig($table_prefix, $app_locale){
if ('cms_' != $table_prefix || 'en' != $app_locale) {
$config_str = str_replace(
["=> 'cms_", "=> 'en"],
["=> '".$table_prefix, "=> '".$app_locale],
file_get_contents(dirname(__FILE__, 3).'/config/laravel-cms.php')
);
$config_str = trim($config_str); // in case it not change in ram memory
file_put_contents(base_path('config/laravel-cms.php'), $config_str);
$this->line('<fg=cyan>----> Changed db table prefix to : </><fg=yellow>'.$table_prefix.'</>');
}
}
}

0 comments on commit e083bdf

Please sign in to comment.