Commit 54c9ad2a authored by Jordan Breton's avatar Jordan Breton

bug fixes in project import/update/create

parent cdf5438f
......@@ -37,7 +37,7 @@ try{
if(count($tmp) > 1){
$l = array_shift($tmp);
$p = implode("/",$tmp);
switch($tmp[0]){
switch($l){
case 'engine' :
$location = "$engine/package/$p";
break;
......@@ -48,19 +48,20 @@ try{
default :
$location = "$location/$p";
}
}
else $location = "$location/".($p = $tmp[0]);
if(is_dir($location)){
$webroot = array_diff(scandir("$location/webroot"),['..','.']);
foreach($webroot as $dir){
if(!is_dir("$site/webroot/$dir")) mkdir("$site/webroot/$dir");
if(is_link("$site/webroot/$dir/$p")) unlink("$site/webroot/$dir/$p");
chdir("$site/webroot/$dir");
if(!$m) $exec("ln -s \"../../../$l/package/$p/webroot/$dir\" \"$p\"");
else $exec("ln -s \"../../../$l/$p/webroot/$dir\" \"$p\"");
}
}else fwrite(STDOUT,"\e[33mWFW_installer UNKNOWN_PACKAGE\e[0m : $package\n");
fwrite(STDOUT,"$package installed.\n");
} else $location = "$location/".($p = $tmp[0]);
if(is_dir("$location")){
if(is_dir("$location/webroot")){
$webroot = array_diff(scandir("$location/webroot"),['..','.']);
foreach($webroot as $dir){
if(!is_dir("$site/webroot/$dir")) mkdir("$site/webroot/$dir");
if(is_link("$site/webroot/$dir/$p")) unlink("$site/webroot/$dir/$p");
chdir("$site/webroot/$dir");
if(!$m) $exec("ln -s \"../../../$l/package/$p/webroot/$dir\" \"$p\"");
else $exec("ln -s \"../../../$l/$p/webroot/$dir\" \"$p\"");
}
fwrite(STDOUT,"$package installed.\n");
}else fwrite(STDOUT,"$package : nothing to do (no webroot folder found).\n");
}else fwrite(STDOUT,"\e[33mWFW_installer UNKNOWN_PACKAGE\e[0m : $package : $location doesn't exists\n");
}
}else if($argvReader->exists('-uninstall')){
$args = $argvReader->get('-uninstall');
......@@ -74,12 +75,12 @@ try{
$l = $tmp[0];
}
else $location = "$location/".($p = $tmp[0]);
if(is_dir($location)){
if(is_dir("$location/webroot")){
$webroot = array_diff(scandir("$location/webroot"),['..','.']);
foreach($webroot as $dir){
unlink("$site/webroot/$dir/$p");
}
}else fwrite(STDOUT,"\e[33mWFW_installer UNKNOWN_PACKAGE\e[0m : $package\n");
}else fwrite(STDOUT,"\e[33mWFW_installer UNKNOWN_PACKAGE\e[0m : $package : $location/webroot doesn't exists\n");
}
}else throw new InvalidArgumentException("Unknown command $argv[1]");
}catch(\InvalidArgumentException $e){
......
......@@ -190,19 +190,23 @@ try{
}
}
fwrite(STDOUT,"$n will be updated...\n");
$clean = false;
if(file_exists("$p/cli/wfw/WFWCleanerLauncher.php")){
fwrite(STDOUT,"Searching for $n directories to clean before import...\n");
$res = [];
exec("$p/cli/wfw/WFWCleanerLauncher.php -update -list",$res);
fwrite(STDOUT,"The following files and directories will be removed : \n");
foreach($res as $line) fwrite(STDOUT,"\t$line\n");
if($prompt){
fwrite(STDOUT,"Do you really want to continue ? (y/n) : ");
if(!filter_var(preg_replace(["/^y$/","/^n$/"],["yes","no"],fgets(STDIN)), FILTER_VALIDATE_BOOLEAN)){
fwrite(STDOUT,"$n will not be updated.\n");
continue;
if(count($res) > 0){
$clean = true;
fwrite(STDOUT,"The following files and directories will be removed : \n");
foreach($res as $line) fwrite(STDOUT,"\t$line\n");
if($prompt){
fwrite(STDOUT,"Do you really want to continue ? (y/n) : ");
if(!filter_var(preg_replace(["/^y$/","/^n$/"],["yes","no"],fgets(STDIN)), FILTER_VALIDATE_BOOLEAN)){
fwrite(STDOUT,"$n will not be updated.\n");
continue;
}
}
}
}else fwrite(STDOUT,"No file or directory to clean up.\n");
}
fwrite(STDOUT,"Starting $n update (working dir : $tmp/$n)...\n");
......@@ -243,11 +247,13 @@ try{
$exec("wfw self service stop -all");
fwrite(STDOUT,"Daemons stoped.\n");
//removing files and folder
fwrite(STDOUT,"Removing files and folders that must be cleaned up...\n");
exec("$p/cli/wfw/WFWCleanerLauncher.php -update",$res,$state);
if($state > 0) fwrite(STDOUT,"An error occured while trying to cleanup $n.\n");
else fwrite(STDOUT,"$n successfully cleaned up.\n");
if($clean){
//removing files and folder
fwrite(STDOUT,"Removing files and folders that must be cleaned up...\n");
exec("$p/cli/wfw/WFWCleanerLauncher.php -update",$res,$state);
if($state > 0) fwrite(STDOUT,"An error occured while trying to cleanup $n.\n");
else fwrite(STDOUT,"$n successfully cleaned up.\n");
}
$exec("cp -R \"$path/.\" \"$p\"");
fwrite(STDOUT,"Updated files imported.\n");
......@@ -318,7 +324,7 @@ try{
fwrite(STDOUT,"Old file $a2confPath removed.\n");
}
fwrite(STDOUT,"Generating apache2 conf file $a2confPath...\n");
$exec("cat \"".dirname(__DIR__)."/wfw/templates/a2-site.conf.template\" | sed -e \"s+@ROOTPATH+$path+g\" >> \"$a2confPath\"");
$exec("cat \"".dirname(__DIR__)."/wfw/templates/a2-site.conf.template\" | sed -e \"s+@ROOTPATH+$args[1]+g\" >> \"$a2confPath\"");
//write the project root path in DB
$data[$args[0]] = $path;
......@@ -371,7 +377,7 @@ try{
unlink($a2confPath);
fwrite(STDOUT,"Old file $a2confPath removed.\n");
}
fwrite(STDOUT,"Generating apache2 conf file $a2confPath...\n");
fwrite(STDOUT,"Generating apache2 conf file $a2confPath with document root at $path...\n");
$exec("cat \"".dirname(__DIR__)."/wfw/templates/a2-site.conf.template\" | sed -e \"s+@ROOTPATH+$path+g\" >> \"$a2confPath\"");
$exec("wfw add $pName $path");
......@@ -739,20 +745,24 @@ try{
exit(0);
}
}
$clean = false;
fwrite(STDOUT,"$path will be imported into $pPath...\n");
if(file_exists("$pPath/cli/wfw/WFWCleanerLauncher.php")){
fwrite(STDOUT,"Searching for $pName files and directories to clean before import...\n");
$res = [];
exec("$pPath/cli/wfw/WFWCleanerLauncher.php -list",$res);
fwrite(STDOUT,"The following files and directories will be removed : \n");
foreach($res as $line) fwrite(STDOUT,"\t$line\n");
if($prompt){
fwrite(STDOUT,"Do you really want to continue ?\n");
if(!filter_var(preg_replace(["/^y$/","/^n$/"],["yes","no"],fgets(STDIN)), FILTER_VALIDATE_BOOLEAN)){
fwrite(STDOUT,"$path will not be imported.\n");
exit(0);
if(count($res) > 0){
$clean = true;
fwrite(STDOUT,"The following files and directories will be removed : \n");
foreach($res as $line) fwrite(STDOUT,"\t$line\n");
if($prompt){
fwrite(STDOUT,"Do you really want to continue ? (y/n) : ");
if(!filter_var(preg_replace(["/^y$/","/^n$/"],["yes","no"],fgets(STDIN)), FILTER_VALIDATE_BOOLEAN)){
fwrite(STDOUT,"$path will not be imported.\n");
exit(0);
}
}
}
}else fwrite(STDOUT,"No file or directory to clean up.\n");
}
$siteConfChanged = false;
if(!$keepConf && file_exists("$path/site/config/conf.json")){
......@@ -765,10 +775,12 @@ try{
fwrite(STDOUT,"Project conf updated.\n");
}
fwrite(STDOUT,"Removing files and folders that must be cleaned up...\n");
exec("$pPath/cli/wfw/WFWCleanerLauncher.php",$res,$state);
if($state > 0) fwrite(STDOUT,"An error occured while trying to cleanup $pName.\n");
else fwrite(STDOUT,"$pName successfully cleaned up.\n");
if($clean){
fwrite(STDOUT,"Removing files and folders that must be cleaned up...\n");
exec("$pPath/cli/wfw/WFWCleanerLauncher.php",$res,$state);
if($state > 0) fwrite(STDOUT,"An error occured while trying to cleanup $pName.\n");
else fwrite(STDOUT,"$pName successfully cleaned up.\n");
}
fwrite(STDOUT,"Copying $path files and folder into $pPath...\n");
$exec("cp -R \"$path/.\" \"$pPath\"");
......@@ -784,7 +796,9 @@ try{
//install packages (will create appropriated symlinks)
$packages = $conf->getArray("server/packages");
if(is_array($packages) && count($packages)>0){
$exec("wfw $pName package -install \"".implode("\" \"",$packages)."\"");
$res = [];
exec("wfw $pName package -install \"".implode("\" \"",$packages)."\"",$res);
if(count($res) > 0) fwrite(STDOUT,implode("\n",$res)."\n");
}
fwrite(STDOUT,"Project packages installed.\n");
......@@ -797,7 +811,7 @@ try{
$a2confPath = dirname(__DIR__)."/wfw/a2.d/$pName.conf";
if(!file_exists($a2confPath)){
fwrite(STDOUT,"Apache2 conf file $a2confPath not found for this project. Generating a new one...\n");
fwrite(STDOUT,"Apache2 conf file $a2confPath not found for this project. Generating a new one with document root at $pPath...\n");
$exec("cat \"".dirname(__DIR__)."/wfw/templates/a2-site.conf.template\" | sed -e \"s+@ROOTPATH+$pPath+g\" >> \"$a2confPath\"");
fwrite(STDOUT,"Apache2 conf file created.\n");
}
......
......@@ -171,6 +171,7 @@ abstract class AbstractConf implements IConf {
if(isset($current->$v)){
$current=$current->$v;
}else{
//if(!($current instanceof stdClass)) $current=new stdClass();
$current->$v=new stdClass();
$current=$current->$v;
}
......
<?php
namespace wfw\engine\core\conf;
/**
* Base descriptor for sites
*/
class DefaultSiteDescriptor extends ModuleDescriptor {
/**
* @return string
*/
public static function root(): string {
return dirname(__DIR__,3)."/site";
}
/**
* @return array
* @throws \ReflectionException
*/
public static function cleanablePaths(): array {
return array_merge(
self::subdirectories("",["webroot"]),
self::subdirectories("webroot",["uploads"])
);
}
}
\ No newline at end of file
......@@ -97,7 +97,8 @@ abstract class ModuleDescriptor implements IModuleDescriptor{
$root = $from ?? static::root();
if(is_dir("$root/$folder")) return array_map(
function($path)use($root,$folder){
return "$root/$folder/$path";
if(empty($folder)) return "$root/$path";
else return "$root/$folder/$path";
},
array_diff(
scandir("$root/$folder"),
......
......@@ -178,9 +178,8 @@ final class WFW extends ModuleDescriptor implements IAppModulesCollector, ISecur
*/
public static function registerModules(string ...$modules): void {
foreach($modules as $module){
if(is_a($module,IModuleDescriptor::class)){
/** @var IModuleDescriptor $module */
self::$_modules[(string)$module] = $module::root();
if(is_a($module,IModuleDescriptor::class,true)){
self::$_modules[] = $module;
}else throw new \InvalidArgumentException(
"$module doesn't implements ".IModuleDescriptor::class
);
......@@ -188,6 +187,9 @@ final class WFW extends ModuleDescriptor implements IAppModulesCollector, ISecur
}
/**
* The default site descriptor is automaticaly appened to the module list if no
* wfw\\site\\config\\SiteDescriptor class exists.
*
* @param string $fileName Name of register files for modules
* modules.
*/
......@@ -197,6 +199,10 @@ final class WFW extends ModuleDescriptor implements IAppModulesCollector, ISecur
$out = [];
exec("find \"$dir\" -type f -name \"*$fileName\" | sort",$out);
foreach($out as $file) require_once $file;
self::$_modules = array_merge(
self::$_modules,
[ class_exists($c = "wfw\\site\\config\\SiteDescriptor") ? $c : DefaultSiteDescriptor::class ]
);
}
}
......@@ -330,7 +336,7 @@ final class WFW extends ModuleDescriptor implements IAppModulesCollector, ISecur
self::subdirectories("cli/installer",[],$from),
self::subdirectories("cli/tester",["config"],$from),
self::subdirectories("cli/webroot",[],$from),
self::subdirectories("cli/wfw",["global.db.json","config"],$from),
self::subdirectories("cli/wfw",["global.db.json","config","a2.d"],$from),
self::subdirectories("cli/zipCode",[],$from),
self::subdirectories("daemons/kvstore",["data","server"],$from),
self::subdirectories("daemons/kvstore/server",["config"],$from),
......
......@@ -57,7 +57,8 @@ final class UpdateHandler implements IActionHandler {
if($report->satisfied()){
$this->_mielPot->set($data['miel_key'],$data['miel_data']);
$this->_mielPot->save();
$this->_cache->deleteAll([IWebAppContext::CACHE_KEYS[IWebAppContext::VIEWS]]);
$this->_cache->deleteAll([IWebAppContext::VIEWS]);
$this->_cache->delete(IMielModel::CACHE_KEY);
return new Response();
}else return new ErrorResponse("201",$this->_translator->get(
"server/engine/package/miel/ERROR"),$report->errors()
......
......@@ -5,6 +5,7 @@ namespace wfw\engine\package\miel\model;
* Liste de valeurs associées à des clés.
*/
interface IMielModel extends \ArrayAccess,\Iterator {
public const CACHE_KEY = "WFW/WebApp/packages/miel/model";
/**
* @param string $key Clé à tester.
* @return bool True si la clé existe, false sinon
......
......@@ -78,7 +78,7 @@ final class PictureViewerOptions implements IPictureViewerOptions {
}
$this->_autoplay = $options['autoplay'] ?? true;
(function(string... $vals){})(...array_values($icons));
$engine = dirname(__DIR__,3);
$engine = dirname(__DIR__,2);
$this->_arrowLeftIcon = $icons['arrow_left'] ?? $engine.'/webroot/Image/svg/icons/left-arrow.svg';
$this->_arrowRightIcon = $icons['arrow_right'] ?? $engine.'/webroot/Image/svg/icons/right-arrow.svg';
$this->_fullscreenOnIcon = $icons['fullscreen_on'] ?? $engine.'/webroot/Image/svg/icons/expand.svg';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment