From 543b99834dd9ec8c609955801476d4eec1ca2a56 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Wed, 13 Feb 2013 09:33:36 -0500
Subject: [PATCH] - App Installer: make sure that package URLs get inserted in aps_packages table even when process of updating the packagelist is aborted or reloaded. - Added an explanation page before package lists are updated.
---
interface/web/sites/lib/module.conf.php | 2
interface/lib/classes/aps_crawler.inc.php | 65 ++++++++++++++++-----
interface/web/sites/aps_update_packagelist.php | 57 +++++++++++++++++++
interface/web/sites/lib/lang/en_aps_update_packagelist.lng | 7 ++
interface/web/sites/lib/lang/de_aps_update_packagelist.lng | 7 ++
interface/web/sites/templates/aps_update_packagelist.htm | 20 ++++++
interface/web/sites/aps_cron_apscrawler_if.php | 4 +
7 files changed, 144 insertions(+), 18 deletions(-)
diff --git a/interface/lib/classes/aps_crawler.inc.php b/interface/lib/classes/aps_crawler.inc.php
index ca3402e..98cf769 100644
--- a/interface/lib/classes/aps_crawler.inc.php
+++ b/interface/lib/classes/aps_crawler.inc.php
@@ -35,7 +35,7 @@
class ApsCrawler extends ApsBase
{
- public $app_download_url_list = array();
+ //public $app_download_url_list = array();
/**
* Constructor
@@ -216,7 +216,7 @@
public function startCrawler()
{
global $app;
-
+
try
{
// Make sure the requirements are given so that this script can execute
@@ -297,13 +297,8 @@
$local_intf_folder = $this->interface_pkg_dir.'/'.$app_name.'-'.$new_ver.'.app.zip/';
// Proceed if a newer or at least equal version has been found with server mode or
- // interface mode is activated and there's no valid APP-META.xml existing yet
- if((!$this->interface_mode && version_compare($new_ver, $ex_ver) >= 0)
- || ($this->interface_mode
- && (!file_exists($local_intf_folder.'APP-META.xml') || filesize($local_intf_folder.'APP-META.xml') == 0)
- )
- )
- {
+ // interface mode is activated and there are no valid APP-META.xml and PKG_URL existing yet
+ if((!$this->interface_mode && version_compare($new_ver, $ex_ver) >= 0) || ($this->interface_mode && (!file_exists($local_intf_folder.'APP-META.xml') || filesize($local_intf_folder.'APP-META.xml') == 0 || !file_exists($local_intf_folder.'PKG_URL') || filesize($local_intf_folder.'PKG_URL') == 0))){
// Check if we already have an old version of this app
if(!empty($ex_ver) && version_compare($new_ver, $ex_ver) == 1) $apps_updated++;
@@ -311,8 +306,7 @@
$app_filesize = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@length");
$app_metafile = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='meta']/@href");
- $this->app_download_url_list[$app_name.'-'.$new_ver.'.app.zip'] = $app_dl;
-
+ //$this->app_download_url_list[$app_name.'-'.$new_ver.'.app.zip'] = $app_dl;
// Skip ASP.net packages because they can't be used at all
$asp_handler = parent::getXPathValue($sxe, '//aspnet:handler');
$asp_permissions = parent::getXPathValue($sxe, '//aspnet:permissions');
@@ -342,6 +336,9 @@
// Create the local folder if not yet existing
if(!file_exists($local_intf_folder)) @mkdir($local_intf_folder, 0777, true);
+
+ // Save the package URL in an extra file because it's not part of the APP-META.xml file
+ @file_put_contents($local_intf_folder.'PKG_URL', $app_dl);
// Download the meta file
$local_metafile = $local_intf_folder.'APP-META.xml';
@@ -480,7 +477,7 @@
try
{
- // This method must be used in server mode
+ // This method must be used in interface mode
if(!$this->interface_mode) return false;
$pkg_list = array();
@@ -531,6 +528,8 @@
$pkg_category = parent::getXPathValue($sxe, '//category');
$pkg_version = parent::getXPathValue($sxe, 'version');
$pkg_release = parent::getXPathValue($sxe, 'release');
+ //$pkg_url = $this->app_download_url_list[$pkg];
+ $pkg_url = @file_get_contents($this->interface_pkg_dir.'/'.$pkg.'/PKG_URL');
/*
$app->db->query("INSERT INTO `aps_packages`
@@ -539,13 +538,17 @@
'".$app->db->quote($pkg_category)."', '".$app->db->quote($pkg_version)."',
".$app->db->quote($pkg_release).", ".PACKAGE_ENABLED.");");
*/
-
- $insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_url`, `package_status`) VALUES
+ // Insert only if data is complete
+ if($pkg != '' && $pkg_name != '' && $pkg_category != '' && $pkg_version != '' && $pkg_release != '' && $pkg_url){
+ $insert_data = "(`path`, `name`, `category`, `version`, `release`, `package_url`, `package_status`) VALUES
('".$app->db->quote($pkg)."', '".$app->db->quote($pkg_name)."',
'".$app->db->quote($pkg_category)."', '".$app->db->quote($pkg_version)."',
- ".$app->db->quote($pkg_release).", '".$app->db->quote($this->app_download_url_list[$pkg])."', ".PACKAGE_ENABLED.");";
+ ".$app->db->quote($pkg_release).", '".$app->db->quote($pkg_url)."', ".PACKAGE_ENABLED.");";
- $app->db->datalogInsert('aps_packages', $insert_data, 'id');
+ $app->db->datalogInsert('aps_packages', $insert_data, 'id');
+ } else {
+ if(file_exists($this->interface_pkg_dir.'/'.$pkg)) $this->removeDirectory($this->interface_pkg_dir.'/'.$pkg);
+ }
}
}
catch(Exception $e)
@@ -555,5 +558,35 @@
return false;
}
}
+
+ /**
+ * Add missing package URLs to database
+ */
+ public function fixURLs()
+ {
+ global $app;
+
+ try
+ {
+ // This method must be used in interface mode
+ if(!$this->interface_mode) return false;
+
+ $incomplete_pkgs = $app->db->queryAllRecords("SELECT * FROM aps_packages WHERE package_url = ''");
+ if(is_array($incomplete_pkgs) && !empty($incomplete_pkgs)){
+ foreach($incomplete_pkgs as $incomplete_pkg){
+ $pkg_url = @file_get_contents($this->interface_pkg_dir.'/'.$incomplete_pkg['path'].'/PKG_URL');
+ if($pkg_url != ''){
+ $app->db->datalogUpdate('aps_packages', "package_url = '".$pkg_url."'", 'id', $incomplete_pkg['id']);
+ }
+ }
+ }
+ }
+ catch(Exception $e)
+ {
+ $app->log($this->log_prefix.$e->getMessage(), LOGLEVEL_ERROR);
+ $app->error($e->getMessage());
+ return false;
+ }
+ }
}
?>
\ No newline at end of file
diff --git a/interface/web/sites/aps_cron_apscrawler_if.php b/interface/web/sites/aps_cron_apscrawler_if.php
index b34b836..d1e15cc 100644
--- a/interface/web/sites/aps_cron_apscrawler_if.php
+++ b/interface/web/sites/aps_cron_apscrawler_if.php
@@ -28,7 +28,8 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
require_once('../../lib/config.inc.php');
-require_once('../../lib/app.inc.php');
+require_once('../../lib/app.inc.php');
+
//require_once('classes/class.crawler.php');
$app->load('aps_crawler');
@@ -44,6 +45,7 @@
$time_start = microtime(true);
$aps->startCrawler();
$aps->parseFolderToDB();
+$aps->fixURLs();
$time = microtime(true) - $time_start;
$app->log($log_prefix.'Used mem at end: '.$aps->convertSize(memory_get_usage(true)));
diff --git a/interface/web/sites/aps_update_packagelist.php b/interface/web/sites/aps_update_packagelist.php
new file mode 100644
index 0000000..10de873
--- /dev/null
+++ b/interface/web/sites/aps_update_packagelist.php
@@ -0,0 +1,57 @@
+<?php
+/*
+Copyright (c) 2012, Till Brehm, projektfarm Gmbh, ISPConfig UG
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of ISPConfig nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+//* Check permissions for module
+$app->auth->check_module_permissions('sites');
+
+$app->uses('tpl');
+
+$app->tpl->newTemplate('form.tpl.htm');
+$app->tpl->setInclude('content_tpl', 'templates/aps_update_packagelist.htm');
+$msg = '';
+$error = '';
+
+//* load language file
+$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_aps_update_packagelist.lng';
+include($lng_file);
+$app->tpl->setVar($wb);
+
+
+
+$app->tpl->setVar('msg',$msg);
+$app->tpl->setVar('error',$error);
+
+$app->tpl_defaults();
+$app->tpl->pparse();
+
+
+?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/lang/de_aps_update_packagelist.lng b/interface/web/sites/lib/lang/de_aps_update_packagelist.lng
new file mode 100644
index 0000000..655825b
--- /dev/null
+++ b/interface/web/sites/lib/lang/de_aps_update_packagelist.lng
@@ -0,0 +1,7 @@
+<?php
+$wb['head_txt'] = 'Paketliste aktualisieren';
+$wb['list_desc_txt'] = '';
+$wb['btn_start_txt'] = 'Paketliste aktualisieren';
+$wb['btn_cancel_txt'] = 'Abbrechen';
+$wb['legend_txt'] = 'Hier können Sie die Liste der verfügbaren Pakete aktualisieren. Dies kann bis zu fünf Minuten dauern. Wenn Sie möchten, können Sie diese Seite verlassen; der Prozeß läuft im Hintergrund weiter.';
+?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/lang/en_aps_update_packagelist.lng b/interface/web/sites/lib/lang/en_aps_update_packagelist.lng
new file mode 100644
index 0000000..1a40a33
--- /dev/null
+++ b/interface/web/sites/lib/lang/en_aps_update_packagelist.lng
@@ -0,0 +1,7 @@
+<?php
+$wb['head_txt'] = 'Update Packagelist';
+$wb['list_desc_txt'] = '';
+$wb['btn_start_txt'] = 'Update Packagelist';
+$wb['btn_cancel_txt'] = 'Cancel';
+$wb['legend_txt'] = 'Here you can update the list of available packages. Please note that this can take up to five minutes. You can leave this page if you like; the process will continue in the background.';
+?>
\ No newline at end of file
diff --git a/interface/web/sites/lib/module.conf.php b/interface/web/sites/lib/module.conf.php
index 982cb90..81d627e 100644
--- a/interface/web/sites/lib/module.conf.php
+++ b/interface/web/sites/lib/module.conf.php
@@ -150,7 +150,7 @@
{
$items[] = array( 'title' => 'Update Packagelist',
'target' => 'content',
- 'link' => 'sites/aps_cron_apscrawler_if.php',
+ 'link' => 'sites/aps_update_packagelist.php',
'html_id' => 'aps_packagedetails_show');
}
diff --git a/interface/web/sites/templates/aps_update_packagelist.htm b/interface/web/sites/templates/aps_update_packagelist.htm
new file mode 100644
index 0000000..bd8edfd
--- /dev/null
+++ b/interface/web/sites/templates/aps_update_packagelist.htm
@@ -0,0 +1,20 @@
+<h2><tmpl_var name="head_txt"></h2>
+<p><tmpl_var name="list_desc_txt"></p>
+
+<div class="panel panel_language_import">
+
+ <div class="pnl_formsarea">
+ <fieldset class="inlineLabels"><legend>{tmpl_var name="legend_txt"}</legend>
+
+ <div class="buttonHolder buttons">
+ <button class="positive iconstxt icoPositive" type="button" value="Update Packagelist" onClick="loadContent('sites/aps_cron_apscrawler_if.php')"><span>{tmpl_var name="btn_start_txt"}</span></button>
+ <button class="negative iconstxt icoNegative" type="button" value="Cancel" onClick="loadContent('sites/aps_availablepackages_list.php');"><span>{tmpl_var name="btn_cancel_txt"}</span></button>
+ </div>
+ </fieldset>
+
+
+
+
+ </div>
+
+</div>
--
Gitblit v1.9.1