Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
add option for clearing target before installing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Molineus committed Sep 16, 2013
1 parent 026e8a7 commit 358151d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
47 changes: 39 additions & 8 deletions src/system/modules/bootstrap/classes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
namespace Netzmacht\Bootstrap;


/**
* Class Installer
* @package Netzmacht\Bootstrap
*/
class Installer extends \Backend
{

/**
* constructor
*/
public function __construct()
{
$this->import('BackendUser', 'User');
Expand All @@ -25,12 +33,23 @@ public function __construct()
$this->loadLanguageFile('modules');
}


/**
* method for runonce.php
*/
public function runOnce()
{
$this->setupSections();
$this->installDependencies();
if($this->User->isAdmin)
{
$this->setupSections();
$this->installDependencies();
}
}


/**
* install all dependencies of bootstrap
*/
protected function installDependencies()
{
require_once TL_ROOT . '/system/modules/bootstrap/config/bootstrap/installer.php';
Expand All @@ -53,6 +72,12 @@ protected function installDependencies()
continue;
}

// remove existing files
if(isset($dependency['clearTarget']) && $dependency['clearTarget'] && is_dir(TL_ROOT . '/' . $dependency['target']))
{
$files->rrdir($dependency['target']);
}

$content = file_get_contents($dependency['file']);

$tempName = tempnam(TL_ROOT . '/system/tmp', 'bootstrap_');
Expand All @@ -79,8 +104,6 @@ protected function installDependencies()
continue;
}

var_dump($dependency['target'] . $fileName);

$file = new \File($dependency['target'] . $fileName);
$file->write($zip->unzip());
$file->close();
Expand All @@ -104,12 +127,12 @@ protected function installDependencies()
$config->save();
}


/**
* setup required sections
*/
protected function setupSections()
{
if(!$this->User->isAdmin) {
return;
}

if($GLOBALS['TL_CONFIG']['customSections'] == '') {
$GLOBALS['TL_CONFIG']['customSections'] = 'bootstrap';
}
Expand All @@ -122,6 +145,14 @@ protected function setupSections()
$config->save();
}


/**
* check if file is in one of the defined paths
* @param $fileName
* @param $paths
*
* @return bool
*/
protected function fileMatchPaths($fileName, $paths)
{
foreach($paths as $path)
Expand Down
25 changes: 14 additions & 11 deletions src/system/modules/bootstrap/config/bootstrap/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

'bootstrap' => array
(
'file' => 'https://github.com/twbs/bootstrap/archive/v3.0.0.zip',
'root' => 'bootstrap-3.0.0/',
'target' => 'assets/bootstrap/bootstrap/',
'paths' => array
'file' => 'https://github.com/twbs/bootstrap/archive/v3.0.0.zip',
'root' => 'bootstrap-3.0.0/',
'target' => 'assets/bootstrap/bootstrap/',
'clearTarget' => true,
'paths' => array
(
'js',
'less',
Expand All @@ -44,17 +45,19 @@

'bootstrap-select' => array
(
'file' => 'https://github.com/silviomoreto/bootstrap-select/archive/1.3.1.zip',
'root' => 'bootstrap-select-1.3.1',
'target' => 'assets/bootstrap/bootstrap-select/',
'file' => 'https://github.com/silviomoreto/bootstrap-select/archive/1.3.1.zip',
'root' => 'bootstrap-select-1.3.1',
'target' => 'assets/bootstrap/bootstrap-select/',
'clearTarget' => true,
),

'jquery-touchSwipe' => array
(
'file' => 'https://github.com/mattbryson/TouchSwipe-Jquery-Plugin/archive/1.6.4.zip',
'root' => 'TouchSwipe-Jquery-Plugin-1.6.4/',
'target' => 'assets/bootstrap/jquery-touchSwipe/',
'paths' => array
'file' => 'https://github.com/mattbryson/TouchSwipe-Jquery-Plugin/archive/1.6.4.zip',
'root' => 'TouchSwipe-Jquery-Plugin-1.6.4/',
'target' => 'assets/bootstrap/jquery-touchSwipe/',
'clearTarget' => true,
'paths' => array
(
'jquery.touchSwipe.min.js',
'README.md'
Expand Down

0 comments on commit 358151d

Please sign in to comment.