Commit 40bc7a89 authored by niclone's avatar niclone

[FIX]mods: moved some code to modslib, making it more re-usable

parent 650c42bf
......@@ -856,7 +856,43 @@ class ModsLib {
}
}
function install_with_deps($modspath, $mods_server, $modnames) {
function install_with_deps($modspath, $mods_server, $deps) {
/* download packages if necessary */
foreach($deps['requires'] as $mod) {
if ($mod->repository == 'remote') {
$res=$this->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$modspath);
if ($res === false) return false;
}
}
foreach($deps['wanted'] as $mod) {
if ($mod->repository == 'remote') {
$res=$this->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$modspath);
if ($res === false) return false;
}
}
// we reconstruct deps because now there are modules that are downloaded
$this->rebuild_list($modspath."/Packages");
/* install packages */
foreach($deps['requires'] as $mod) {
$this->install($modspath, $mod);
}
foreach($deps['wanted'] as $mod) {
$this->install($modspath, $mod);
}
}
function remove_with_deps($modspath, $mods_server, $deps) {
foreach($deps['toremove'] as $mod) {
$this->remove($modspath, $mod);
}
}
function install($path,$mod,$from=0,$upgrade=false) {
......
......@@ -100,44 +100,7 @@ function command_install($goption, $coption, $cparams) {
exit(0);
}
$res=NULL;
/* download packages if necessary */
if ($res !== false) foreach($deps['requires'] as $mod) {
if ($mod->repository == 'remote') {
echo "downloading: ".$mod->modname.'-'.$mod->revision." ...";
$res=$modslib->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$mods_dir);
if ($res === false)
break;
}
}
if ($res !== false) foreach($deps['wanted'] as $mod) {
if ($mod->repository == 'remote') {
$res=$modslib->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$mods_dir);
if ($res === false)
break;
}
}
// we reconstruct deps because now there are modules that are downloaded
// (this is mainly to re-read_list the local repository)
$modslib->rebuild_list($mods_dir."/Packages");
$deps=$modslib->find_deps($mods_dir, $mods_server, $cparams);
if (in_array('-d', $coption)) return;
/* install packages */
if ($res !== false) foreach($deps['requires'] as $mod) {
$modslib->install($mods_dir, $mod);
}
if ($res !== false) foreach($deps['wanted'] as $mod) {
$modslib->install($mods_dir, $mod);
}
$modslib->install_with_deps($mods_dir, $mods_server, $deps);
}
function command_remove($goption, $coption, $cparams) {
......@@ -168,14 +131,7 @@ function command_remove($goption, $coption, $cparams) {
$res=NULL;
/* remove packages */
if ($res !== false) foreach($deps['toremove'] as $mod) {
echo "removing ".$mod->modname." (".$mod->revision.")...";
$modslib->remove($mods_dir, $mod);
echo "done.\n";
}
$modslib->remove_with_deps($mods_dir, $mods_server, $deps);
}
function command_list($goption, $coption, $cparams) {
......
<?php
// $Header: /cvsroot/tikiwiki/tiki/tiki-mods.php,v 1.13 2007-03-17 14:58:23 niclone Exp $
// $Header: /cvsroot/tikiwiki/tiki/tiki-mods.php,v 1.14 2007-03-17 16:29:24 niclone Exp $
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
......@@ -147,47 +147,10 @@ if (isset($_REQUEST['action']) and isset($package) and $iswritable) {
}
} elseif (isset($_REQUEST['button-install'])) {
$deps=$modslib->find_deps($mods_dir, $mods_server, $_REQUEST['install-wants']);
$res=NULL;
/* download packages if necessary */
if ($res !== false) foreach($deps['requires'] as $mod) {
if ($mod->repository == 'remote') {
$res=$modslib->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$mods_dir);
if ($res === false) break;
}
}
if ($res !== false) foreach($deps['wanted'] as $mod) {
if ($mod->repository == 'remote') {
$res=$modslib->dl_remote($mods_server,$mod->modname.'-'.$mod->revision,$mods_dir);
if ($res === false) break;
}
}
// we reconstruct deps because now there are modules that are downloaded
// (this is mainly to re-read_list the local repository)
$modslib->rebuild_list($mods_dir."/Packages");
$deps=$modslib->find_deps($mods_dir, $mods_server, $_REQUEST['install-wants']);
/* install packages */
if ($res !== false) foreach($deps['requires'] as $mod) {
$modslib->install($mods_dir, $mod);
}
if ($res !== false) foreach($deps['wanted'] as $mod) {
$modslib->install($mods_dir, $mod);
}
$modslib->install_with_deps($mods_dir, $mods_server, $deps);
} elseif (isset($_REQUEST['button-remove'])) {
$deps=$modslib->find_deps_remove($mods_dir, $mods_server, $_REQUEST['install-wants']);
/* remove packages to remove */
foreach($deps['toremove'] as $mod) {
$modslib->remove($mods_dir, $mod);
}
$modslib->remove_with_deps($mods_dir, $mods_server, $deps);
}
$local = $modslib->read_list($mods_dir."/Packages/00_list.txt",'local',$type,$find,false);
......
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