Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Code Cleanup
  • Loading branch information
andreherberth committed Sep 7, 2018
1 parent bf43018 commit 9a83688
Showing 1 changed file with 19 additions and 39 deletions.
58 changes: 19 additions & 39 deletions installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function __construct($installpath, $temppath)

/**
* phlog - For logging things.
* @param $type
* @param $msg
* @param $filename
* @param $type - Event type
* @param $msg - Log Description
* @param $filename - Name of logfile
*/
public function phlog($type, $msg, $filename)
{
Expand All @@ -45,12 +45,16 @@ public function phlog($type, $msg, $filename)
file_put_contents($this->tpath . $filename, $log, FILE_APPEND | LOCK_EX);
}

/**
* phstatus
* @return string - Current Status
*/
public function phstatus()
{

$i = "prepare1";

if ( file_exists($this->tpath . 'vendor/autoload.php')
if ( file_exists($this->tpath . 'composer/vendor/autoload.php')
&& file_exists($this->tpath . 'unpack.done') ) {

if ( file_exists($this->tpath . 'bazaar.done' ) ) {
Expand Down Expand Up @@ -94,43 +98,17 @@ private function phgetfile($src)

}

public function getComposer()
private function getComposer()
{
touch($this->tpath . 'unpack.start');
if ( !file_exists($this->tpath . 'composer.phar') ) {
$this->phgetfile('https://getcomposer.org/composer.phar');
}
$composer = new Phar($this->tpath . "composer.phar");
$composer->extractTo($this->tpath);
$composer->extractTo($this->tpath . 'composer/');
touch($this->tpath . 'unpack.done');
}

/**
* Count lines of file.
* @param $file
* @return int
*/
public function phlines ($file)
{
$lines = 0;
$file = fopen( $file, 'r');

while( !feof( $file) ) {

fgets($file);

$lines++;
}

fclose( $file);
return $lines;
}

/**
* getfile($src, $dest) - downloads a file and saves it on the web server.
*
* @param $dir
*/
function rrmdir($dir)
{
if ( is_dir($dir) ) {
Expand All @@ -154,7 +132,7 @@ function rrmdir($dir)
* @param String $dest - Destination of files being moved
* @return NULL
*/
function rmove($src, $dest)
private function rmove($src, $dest)
{

// If source is not a directory stop processing
Expand All @@ -181,7 +159,7 @@ function rmove($src, $dest)
unlink($src);
}

public function phcomposer($command, $taskname)
private function phcomposer($command, $taskname)
{
touch($this->tpath . $taskname .'.log');
touch($this->tpath . $taskname . '.start');
Expand All @@ -194,7 +172,7 @@ public function phcomposer($command, $taskname)

ignore_user_abort(true);
set_time_limit(1100);
require_once($this->tpath . 'vendor/autoload.php');
require_once($this->tpath . 'composer/vendor/autoload.php');

$this->phlog('Composer:', 'Starting Create-Project ' . $taskname, 'install.log');
putenv('COMPOSER_HOME=' . $this->tpath);
Expand All @@ -220,7 +198,7 @@ public function phcomposer($command, $taskname)
return 'done';
}

function listen($request)
public function listen($request)
{
$allowed = array('status','prepare1','flarum','bazaar','cleanup','log', progress);
if(!in_array($request,$allowed)) {
Expand All @@ -232,7 +210,7 @@ function listen($request)
}
}

function process($request)
public function process($request)
{
$status = $this->phstatus();
if ($request == $status) {
Expand Down Expand Up @@ -266,7 +244,8 @@ function process($request)
echo $logfile;
}
}
function cleanup() {

private function cleanup() {

$this->rmove($this->ipath . "flarumtemp", $this->ipath);
//Removes temporary directory
Expand All @@ -280,8 +259,9 @@ function cleanup() {
* composerProgress($file) - Returns amount of finished vendors and the total. Composer output.
*
* @param $file
* @return string
*/
function composerProgress($file){
public function composerProgress($file){
$log_file = file_get_contents($this->tpath . $file);
$result = "<pre id='consoleoutput' style='white-space: pre-wrap; text-align:left; height: 300px; max-height: 300px; overflow:auto; color:#fff;'>" . $log_file . "</pre>";
return $result;
Expand Down

0 comments on commit 9a83688

Please sign in to comment.