- add support for multiple directories

This commit is contained in:
Andreas Burchert (scarya)
2010-10-20 20:29:47 +00:00
parent 05897c3e01
commit b58a9d3b88
2 changed files with 100 additions and 91 deletions

View File

@@ -1,89 +1,98 @@
<?php <?php
/** /**
* Deploy File Creator Class * Deploy File Creator Class
* *
* This class creates the deploy file. * This class creates the deploy file.
* *
* PHP version 5 * PHP version 5
* *
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors). * Copyright (c) 2010 the Froxlor Team (see authors).
* *
* For the full copyright and license information, please view the COPYING * For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the * file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
* *
* @category FroxlorCore * @category FroxlorCore
* @package Classes * @package Classes
* @subpackage System * @subpackage System
* @author Froxlor Team <team@froxlor.org> * @author Froxlor Team <team@froxlor.org>
* @copyright 2010 the authors * @copyright 2010 the authors
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @version SVN: $Id: class.FroxlorPkgCreator.php 1376 2010-10-20 19:07:51Z scarya $ * @version SVN: $Id$
* @link http://www.froxlor.org/ * @link http://www.froxlor.org/
*/ */
/** /**
* Class FroxlorDeployfileCreator * Class FroxlorDeployfileCreator
* *
* This class creates the deploy file. * This class creates the deploy file.
* *
* @category FroxlorCore * @category FroxlorCore
* @package Classes * @package Classes
* @subpackage System * @subpackage System
* @author Froxlor Team <team@froxlor.org> * @author Froxlor Team <team@froxlor.org>
* @copyright 2010 the authors * @copyright 2010 the authors
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @link http://www.froxlor.org/ * @link http://www.froxlor.org/
*/ */
class FroxlorDeployfileCreator class FroxlorDeployfileCreator
{ {
public static $_list = null; /**
* Contains the file listing.
/** *
* This function iterates through the $dir and generates the deploy list. * @var array
* */
* @param string $dir dir to deploy public static $_list = null;
*
* @return array file listing /**
*/ * This function iterates through the $dir and generates the deploy list.
public static function createList($dir) *
{ * @param array $dir dir to deploy
$list = array(); *
* @return array file listing
if (is_dir($dir)) { */
$its = new RecursiveIteratorIterator( public static function createList($dirList)
new RecursiveDirectoryIterator($dir) {
); $list = array();
foreach ($its as $fullFileName => $it ) { foreach ($dirList as $dir) {
if (!preg_match("/userdata.inc.php$/i", $it->getFilename())) { if (is_dir($dir)) {
$list[] = strstr($fullFileName, "lib/"); $its = new RecursiveIteratorIterator(
} new RecursiveDirectoryIterator($dir)
} );
} foreach ($its as $fullFileName => $it ) {
if (!preg_match("/(userdata.inc.php|navigation|configfiles)/i", $it->getFilename())) {
self::$_list = $list; $list[] = $fullFileName;
}
return $list; }
}
} else {
/** throw new Exception($dir." is not a directory!");
* This function saves the deploy list to a file. }
* }
* @param string $toPath file path
* @param array $list array list with all needed files self::$_list = $list;
*
* @return boolean return $list;
*/ }
public static function saveListTo($toPath, $list = null)
{ /**
if (is_null($list)) { * This function saves the deploy list to a file.
$list = self::$_list; *
} * @param string $toPath file path
* @param array $list array list with all needed files
return file_put_contents($toPath, implode("\n", $list)); *
} * @return boolean
*/
public static function saveListTo($toPath, $list = null)
{
if (is_null($list)) {
$list = self::$_list;
}
return file_put_contents($toPath, implode("\n", $list));
}
} }

View File

@@ -69,7 +69,7 @@ class FroxlorPkgCreator
// parse the config // parse the config
if (!$this->_checkConfig()) { if (!$this->_checkConfig()) {
die("Error in FroxlorPkgCreator::_checkConfig()"); throw new Exception("Error in FroxlorPkgCreator::_checkConfig()");
} }
$this->pack($toPath); $this->pack($toPath);
@@ -99,7 +99,6 @@ class FroxlorPkgCreator
private function _checkConfig() private function _checkConfig()
{ {
foreach ($this->_config as $key => $var) { foreach ($this->_config as $key => $var) {
// TODO maybe more excluded files?
if (strstr($var, "userdata.inc")) { if (strstr($var, "userdata.inc")) {
// delete this entry // delete this entry
unset($this->_config[$key]); unset($this->_config[$key]);
@@ -132,7 +131,8 @@ class FroxlorPkgCreator
if ($zip->open($toPath, ZIPARCHIVE::OVERWRITE)) { if ($zip->open($toPath, ZIPARCHIVE::OVERWRITE)) {
// write data // write data
foreach ($this->_config as $var) { foreach ($this->_config as $var) {
$zip->addFile($var, strstr($var, "lib/")); $name = str_replace("froxlor/", "", strstr($var, "froxlor/"));
$zip->addFile($var, $name);
} }
// close it // close it