Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
9d230984
Commit
9d230984
authored
Oct 25, 2018
by
ruchitVC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate quick app installation script
parent
9ff78f8c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
433 additions
and
0 deletions
+433
-0
InstallAppCommand.php
app/Console/Commands/InstallAppCommand.php
+277
-0
Kernel.php
app/Console/Kernel.php
+2
-0
helpers.php
app/Helpers/helpers.php
+17
-0
config-variables.php
config/config-variables.php
+7
-0
laravel_admin_panel.sql
database/dump/laravel_admin_panel.sql
+99
-0
install.sh
install.sh
+31
-0
No files found.
app/Console/Commands/InstallAppCommand.php
0 → 100644
View file @
9d230984
<?php
namespace
App\Console\Commands
;
use
Illuminate\Console\Command
;
use
Illuminate\Filesystem\Filesystem
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\File
;
use
PDOException
;
use
Symfony\Component\Console\Helper\SymfonyQuestionHelper
;
use
Symfony\Component\Console\Question\Question
;
/**
* Class InstallAppCommand.
*
* @author Ruchit Patel
*/
class
InstallAppCommand
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'install:app'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Installation of laravel admin panel.'
;
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected
$files
;
/**
* InstallAppCommand constructor.
*
* @param Filesystem $files
*/
public
function
__construct
(
Filesystem
$files
)
{
parent
::
__construct
();
$this
->
files
=
$files
;
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$this
->
line
(
'------------------'
);
$this
->
line
(
'Welcome to Laravel Admin Panel.'
);
$this
->
line
(
'------------------'
);
exec
(
'composer install'
);
// composer install
$extensions
=
get_loaded_extensions
();
$require_extensions
=
[
'mbstring'
,
'openssl'
,
'curl'
,
'exif'
,
'fileinfo'
,
'tokenizer'
];
foreach
(
array_diff
(
$require_extensions
,
$extensions
)
as
$missing_extension
)
{
$this
->
error
(
'Missing '
.
ucfirst
(
$missing_extension
)
.
' extension'
);
}
if
(
!
file_exists
(
'.env'
))
{
File
::
copy
(
'.env.example'
,
'.env'
);
}
// Set database credentials in .env and migrate
$this
->
setDatabaseInfo
();
$this
->
line
(
'------------------'
);
//Key Generate
Artisan
::
call
(
'key:generate'
);
$this
->
line
(
'Key generated in .env file!'
);
$this
->
line
(
'------------------'
);
//Cache Clear
Artisan
::
call
(
'cache:clear'
);
$this
->
info
(
'Application cache cleared!'
);
$this
->
line
(
'------------------'
);
//Route Clear
Artisan
::
call
(
'route:clear'
);
$this
->
info
(
'Route cache cleared!'
);
$this
->
line
(
'------------------'
);
//Config Clear
Artisan
::
call
(
'config:clear'
);
$this
->
info
(
'Configuration cache cleared!'
);
$this
->
line
(
'------------------'
);
//View Clear
Artisan
::
call
(
'view:clear'
);
$this
->
info
(
'Compiled view cleared!'
);
$this
->
line
(
'------------------'
);
$this
->
info
(
'Now you can access the application on below url!'
);
$this
->
line
(
'Laravel development server started: <http://127.0.0.1:8000>'
);
Artisan
::
call
(
'serve'
);
}
/**
* Set Database info in .env file.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return void
*/
protected
function
setDatabaseInfo
()
{
$this
->
info
(
'Setting up database (please make sure you have created database for this site or not to worry you can dump from here)...!'
);
$this
->
host
=
env
(
'DB_HOST'
);
$this
->
port
=
env
(
'DB_PORT'
);
$this
->
database
=
env
(
'DB_DATABASE'
);
$this
->
username
=
env
(
'DB_USERNAME'
);
$this
->
password
=
env
(
'DB_PASSWORD'
);
while
(
!
checkDatabaseConnection
())
{
// Ask for database details
$this
->
host
=
$this
->
ask
(
'Enter a host name?'
,
config
(
'config-variables.default_db_host'
));
$this
->
port
=
$this
->
ask
(
'Enter a database port?'
,
config
(
'config-variables.default_db_port'
));
$this
->
database
=
$this
->
ask
(
'Enter a database name'
,
$this
->
guessDatabaseName
());
$this
->
username
=
$this
->
ask
(
'What is your MySQL username?'
,
config
(
'config-variables.default_db_username'
));
$question
=
new
Question
(
'What is your MySQL password?'
,
'<none>'
);
$question
->
setHidden
(
true
)
->
setHiddenFallback
(
true
);
$this
->
password
=
(
new
SymfonyQuestionHelper
())
->
ask
(
$this
->
input
,
$this
->
output
,
$question
);
if
(
$this
->
password
===
'<none>'
)
{
$this
->
password
=
''
;
}
// Update DB credentials in .env file.
$contents
=
$this
->
getKeyFile
();
$contents
=
preg_replace
(
'/('
.
preg_quote
(
'DB_HOST='
)
.
')(.*)/'
,
'DB_HOST='
.
$this
->
host
,
$contents
);
$contents
=
preg_replace
(
'/('
.
preg_quote
(
'DB_PORT='
)
.
')(.*)/'
,
'DB_PORT='
.
$this
->
port
,
$contents
);
$contents
=
preg_replace
(
'/('
.
preg_quote
(
'DB_DATABASE='
)
.
')(.*)/'
,
'DB_DATABASE='
.
$this
->
database
,
$contents
);
$contents
=
preg_replace
(
'/('
.
preg_quote
(
'DB_USERNAME='
)
.
')(.*)/'
,
'DB_USERNAME='
.
$this
->
username
,
$contents
);
$contents
=
preg_replace
(
'/('
.
preg_quote
(
'DB_PASSWORD='
)
.
')(.*)/'
,
'DB_PASSWORD='
.
$this
->
password
,
$contents
);
if
(
!
$contents
)
{
throw
new
Exception
(
'Error while writing credentials to .env file.'
);
}
// Write to .env
$this
->
files
->
put
(
'.env'
,
$contents
);
// Set DB username and password in config
$this
->
laravel
[
'config'
][
'database.connections.mysql.username'
]
=
$this
->
username
;
$this
->
laravel
[
'config'
][
'database.connections.mysql.password'
]
=
$this
->
password
;
// Clear DB name in config
unset
(
$this
->
laravel
[
'config'
][
'database.connections.mysql.database'
]);
if
(
!
checkDatabaseConnection
())
{
$this
->
error
(
'Can not connect to database!'
);
}
else
{
$this
->
info
(
'Connected successfully!'
);
}
}
$this
->
createDatabase
(
$this
->
database
);
// create database if not exists.
if
(
$this
->
confirm
(
'You want to dump database sql ?'
))
{
$this
->
dumpDB
(
$this
->
database
);
}
else
{
$this
->
migrateTables
(
$this
->
database
);
}
}
/**
* Guess database name from app folder.
*
* @return string
*
* @author Ruchit Patel
*/
protected
function
guessDatabaseName
()
{
try
{
$segments
=
array_reverse
(
explode
(
DIRECTORY_SEPARATOR
,
app_path
()));
$name
=
explode
(
'.'
,
$segments
[
1
])[
0
];
return
str_replace
(
'-'
,
'_'
,
str_slug
(
$name
));
}
catch
(
Exception
$e
)
{
return
''
;
}
}
/**
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return string
*
* @author Ruchit Patel
*/
protected
function
getKeyFile
()
{
return
$this
->
files
->
exists
(
'.env'
)
?
$this
->
files
->
get
(
'.env'
)
:
$this
->
files
->
get
(
'.env.example'
);
}
/**
* @param $database
*/
protected
function
createDatabase
(
$database
)
{
if
(
!
$database
)
{
$this
->
info
(
'Skipping creation of database as env(DB_DATABASE) is empty'
);
return
;
}
try
{
$query
=
"CREATE DATABASE IF NOT EXISTS
$database
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
;
if
(
DB
::
statement
(
$query
))
{
$this
->
info
(
"Successfully created
$database
database"
);
}
else
{
$this
->
info
(
'Oops, Something went wrong, please try again or create database manually!'
);
}
return
;
}
catch
(
PDOException
$exception
)
{
$this
->
error
(
sprintf
(
'Failed to create %s database, %s'
,
$database
,
$exception
->
getMessage
()));
return
;
}
}
/**
* @param $database
*/
protected
function
dumpDB
(
$database
)
{
if
(
!
empty
(
$database
))
{
// Force the new login to be used
DB
::
purge
();
// Switch to use {$this->database}
DB
::
unprepared
(
'USE `'
.
$database
.
'`'
);
DB
::
connection
()
->
setDatabaseName
(
$database
);
$dumpDB
=
DB
::
unprepared
(
file_get_contents
(
base_path
()
.
'/database/dump/laravel_admin_panel.sql'
));
if
(
$dumpDB
)
{
$this
->
info
(
'Import default database successfully!'
);
}
}
}
/**
* @param $database
*/
protected
function
migrateTables
(
$database
)
{
if
(
$this
->
confirm
(
'You want to migrate tables?'
))
{
// Switch to use {$this->database}
DB
::
unprepared
(
'USE `'
.
$database
.
'`'
);
//DB::connection()->setDatabaseName($this->database);
Artisan
::
call
(
'migrate'
);
$this
->
info
(
'Migration successfully done!'
);
if
(
$this
->
confirm
(
'You want to seeding your database?'
))
{
Artisan
::
call
(
'db:seed'
);
$this
->
info
(
'Seeding successfully done!'
);
}
}
}
}
app/Console/Kernel.php
View file @
9d230984
...
...
@@ -2,6 +2,7 @@
namespace
App\Console
;
use
App\Console\Commands\InstallAppCommand
;
use
Illuminate\Console\Scheduling\Schedule
;
use
Illuminate\Foundation\Console\Kernel
as
ConsoleKernel
;
...
...
@@ -13,6 +14,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected
$commands
=
[
InstallAppCommand
::
class
,
];
/**
...
...
app/Helpers/helpers.php
View file @
9d230984
...
...
@@ -274,3 +274,20 @@ if (!function_exists('isActiveMenuItem')) {
return
false
;
}
}
if
(
!
function_exists
(
'checkDatabaseConnection'
))
{
/**
* @return bool
*/
function
checkDatabaseConnection
()
{
try
{
DB
::
connection
()
->
reconnect
();
return
true
;
}
catch
(
Exception
$ex
)
{
return
false
;
}
}
}
config/config-variables.php
0 → 100644
View file @
9d230984
<?php
return
[
'default_db_host'
=>
'localhost'
,
'default_db_port'
=>
3306
,
'default_db_username'
=>
'root'
,
];
database/dump/laravel_admin_panel.sql
0 → 100644
View file @
9d230984
SET
SQL_MODE
=
"NO_AUTO_VALUE_ON_ZERO"
;
SET
time_zone
=
"+00:00"
;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */
;
/*!40101 SET NAMES utf8mb4 */
;
--
-- Database: `laravel_adminpanel`
--
--
-- Table structure for table `migrations`
--
CREATE
TABLE
`migrations`
(
`id`
int
(
10
)
UNSIGNED
NOT
NULL
,
`migration`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`batch`
int
(
11
)
NOT
NULL
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
--
-- Dumping data for table `migrations`
--
INSERT
INTO
`migrations`
(
`id`
,
`migration`
,
`batch`
)
VALUES
(
1
,
'2014_10_12_000000_create_users_table'
,
1
),
(
2
,
'2014_10_12_100000_create_password_resets_table'
,
1
);
-- --------------------------------------------------------
--
-- Table structure for table `password_resets`
--
CREATE
TABLE
`password_resets`
(
`email`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`token`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`created_at`
timestamp
NULL
DEFAULT
NULL
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE
TABLE
`users`
(
`id`
int
(
10
)
UNSIGNED
NOT
NULL
,
`name`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`email`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`password`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`remember_token`
varchar
(
100
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
,
`created_at`
timestamp
NULL
DEFAULT
NULL
,
`updated_at`
timestamp
NULL
DEFAULT
NULL
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `migrations`
--
ALTER
TABLE
`migrations`
ADD
PRIMARY
KEY
(
`id`
);
--
-- Indexes for table `password_resets`
--
ALTER
TABLE
`password_resets`
ADD
KEY
`password_resets_email_index`
(
`email`
);
--
-- Indexes for table `users`
--
ALTER
TABLE
`users`
ADD
PRIMARY
KEY
(
`id`
),
ADD
UNIQUE
KEY
`users_email_unique`
(
`email`
);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `migrations`
--
ALTER
TABLE
`migrations`
MODIFY
`id`
int
(
10
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,
AUTO_INCREMENT
=
4
;
--
-- AUTO_INCREMENT for table `users`
--
ALTER
TABLE
`users`
MODIFY
`id`
int
(
10
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */
;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
;
install.sh
0 → 100644
View file @
9d230984
#!/usr/bin/env bash
osType
=
$(
uname
)
if
[[
"
$osType
"
==
'Linux'
]]
;
then
sudo chmod
-R
777 ./
fi
echo
-e
"
\0
33[32mCopy .env file...
\0
33[0m"
php
-r
"file_exists('.env') || copy('.env.example', '.env');"
echo
"-----------------------------------------"
echo
-e
"
\0
33[32mNpm version:
\0
33[0m"
npm
-v
echo
"-----------------------------------------"
echo
-e
"
\0
33[32mPHP version:
\0
33[0m"
php
-v
echo
"-----------------------------------------"
echo
-e
"
\0
33[32mCurrent enable PHP Modules:
\0
33[0m"
php
-m
echo
"-----------------------------------------"
echo
-e
"
\0
33[32mStarting install laravel admin panel...
\0
33[0m"
composer
install
composer dump-autoload
php artisan
install
:app
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment