modexport.php
Verfasst: Do 18. Jan 2007, 19:22
Dieses PHP Script exportiert alle Modules eines Clienten auf einmal, serverseitig ins Filesystem.
Vielleicht kann jemand sowas gebrauchen. ?
HIer noch ein paar Hintergrundinfos:
// Subdirectory tools/modules muss existieren und für den Webserver schreibbar sein .
Die export() Funktion von cApiModule erlaubt es den Quelltext eines Moduls entweder zum Browser rauszuschicken, oder die Datei serverseitig im Filesystem abzulegen.
Wenn man die Datei serverseitig ablegen will, werden möglw. die (back-)slashes aus dem Modultext entfernt.
Es gibt dabei noch andere Probleme , besonders beim Re-Import von Modultexten, und mit Sonderzeichen in Dateinamen.
Siehe
http://contenido.org/forum/viewtopic.ph ... port+modul
... führt alles ziemlich weit
Vielleicht kann jemand sowas gebrauchen. ?
HIer noch ein paar Hintergrundinfos:
// Subdirectory tools/modules muss existieren und für den Webserver schreibbar sein .
Die export() Funktion von cApiModule erlaubt es den Quelltext eines Moduls entweder zum Browser rauszuschicken, oder die Datei serverseitig im Filesystem abzulegen.
Wenn man die Datei serverseitig ablegen will, werden möglw. die (back-)slashes aus dem Modultext entfernt.
Es gibt dabei noch andere Probleme , besonders beim Re-Import von Modultexten, und mit Sonderzeichen in Dateinamen.
Siehe
http://contenido.org/forum/viewtopic.ph ... port+modul
... führt alles ziemlich weit
Code: Alles auswählen
<?php
/* $Id: modexport.php 213 2007-01-18 17:29:09Z knb $ */
/* aufrufen: CONTENIDO_HTML_PATH/contenido/tools/modexport.php?action=exportAll&idclient=1 */
/* exportiere alle Module eines Clienten in ein Verzeichnis auf dem Server */
/* danach dann alle Module per FTP (oder so) vom Server holen, in SVN einchecken */
/* Achtung: re-import kann problematisch werden, siehe */
/* http://contenido.org/forum/viewtopic.php?t=13099&highlight=export+modul */
/* fest verdrahtet: */
/* Ordnername "modules" */
include_once ('../includes/startup.php');
cInclude("classes", "contenido/class.module.php");
cInclude("classes", "class.xmltree.php");
cInclude("includes", "functions.mod.php");
cInclude("includes", "functions.con.php");
switch ($_GET["action"])
{
case "list" :
if (!array_key_exists("idclient", $_GET))
{
die;
}
listModules($_GET["idclient"]);
break;
case "exportAll":
exportAllModules($_GET["idclient"]);
break;
}
function exportModule($idmod, $path)
{
//knb 20070118
$cApiModuleCollection = new cApiModuleCollection;
$cApiModuleCollection->setWhere("idmod", $idmod);
$cApiModuleCollection->query();
if ($cApiModule = $cApiModuleCollection->next())
{
$name = preg_replace('/ /', "_", $cApiModule->get("name"));
$name = preg_replace('/[\(\)äöüß]/', "", $name);
$fn = $path . $name .".xml";
//echo "exporting $path, " . $cApiModule->get("name") . " \n";
//don't know if we really need this
setSystemProperty("modules", "storeasfiles", "true");
$cApiModule->_shouldStoreToFile();
file_put_contents($fn, $cApiModule->export($fn, true));
return "xml-exported to $fn\n<br>";
}
}
function exportAllModules($idclient)
{
//knb 20070118
$cApiModuleColl = new cApiModuleCollection;
$cApiModuleColl->setWhere("idclient", $idclient);
$cApiModuleColl->query();
$client = getClientName($idclient);
if (! 1 >= $cApiModuleColl->count() ){
die("There are no modules for idclient $idclient (" . $client . ")");
}
$sOutMsg = "Result of Module Export, Client $client ($idclient):\n<br>";
echo $sOutMsg;;
flush();
while ($cApiMod = $cApiModuleColl->next())
{
// subdirectory tools/modules must exist and must be writable. otherwise, export fails.
$sRootPath = getcwd() ."/modules/" . $client . "/";
if (!is_dir($sRootPath))
{
mkdir($sRootPath );
}
$sOutMsg .= exportModule($cApiMod->get("idmod"), $sRootPath);
}
echo "$sOutMsg\n finished.\n<br><br>Now ftp-get the files to your local hard drive.<br>Don't let modules be accessible from the internet.";
}
function listModules($idclient)
{
$cApiModuleCollection = new cApiModuleCollection;
$cApiModuleCollection->setWhere("idclient", $idclient);
$cApiModuleCollection->query();
$tree = new XmlTree('1.0', 'ISO-8859-1');
$root =& $tree->addRoot('modules');
while ($cApiModule = $cApiModuleCollection->next())
{
$root->appendChild("module", false, array("id" => $cApiModule->get("idmod"), "name" => $cApiModule->get("name")));
}
/* echo "<html><head><title>Modules in client $idclient</title></head><body><h1>Modules in client $idclient</h1><pre>";
flush();
echo "" . */
$tree->dump(true) ;
/*. "</pre></body></html>";*/
}
?>