From 3bb000ee036204c5a3b8dca72df4397cd7cd2cfe Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Thu, 24 Jan 2013 10:35:19 -0500
Subject: [PATCH] - Added PHP-FPM to clients'/resellers' default PHP modes.
---
interface/lib/classes/aps_crawler.inc.php | 93 +++++++++++++++++++++++++++++-----------------
1 files changed, 59 insertions(+), 34 deletions(-)
diff --git a/interface/lib/classes/aps_crawler.inc.php b/interface/lib/classes/aps_crawler.inc.php
index 640bb34..ca3402e 100644
--- a/interface/lib/classes/aps_crawler.inc.php
+++ b/interface/lib/classes/aps_crawler.inc.php
@@ -34,6 +34,9 @@
class ApsCrawler extends ApsBase
{
+
+ public $app_download_url_list = array();
+
/**
* Constructor
*
@@ -51,6 +54,8 @@
*/
private function checkRequirements()
{
+ global $app;
+
try
{
// Check if allow_url_fopen is enabled
@@ -58,7 +63,7 @@
// Check if the cURL module is available
if(!function_exists('curl_version')) throw new Exception('cURL is not available');
- // Check if used folders are writable (chmod 777)
+ // Check if used folders are writable
if($this->interface_mode)
{
if(!is_writable($this->interface_pkg_dir))
@@ -74,7 +79,7 @@
}
catch(Exception $e)
{
- $this->app->log($this->log_prefix.'Aborting execution because '.$e->getMessage(), LOGLEVEL_ERROR);
+ $app->log($this->log_prefix.'Aborting execution because '.$e->getMessage(), LOGLEVEL_ERROR);
return false;
}
}
@@ -197,11 +202,12 @@
* A method to build query URLs out of a list of vendors
*
*/
- private function formatVendorCallback(&$array_item, $key)
+ private function formatVendorCallback($array_item)
{
$array_item = str_replace(' ', '%20', $array_item);
$array_item = str_replace('http://', '', $array_item);
$array_item = '/'.$this->aps_version.'.atom?vendor='.$array_item.'&pageSize=100';
+ return($array_item);
}
/**
@@ -209,6 +215,8 @@
*/
public function startCrawler()
{
+ global $app;
+
try
{
// Make sure the requirements are given so that this script can execute
@@ -216,7 +224,7 @@
if(!$req_ret) return false;
// Execute the open task and first fetch all vendors (APS catalog API 1.1, p. 12)
- $this->app->log($this->log_prefix.'Fetching data from '.$this->fetch_url);
+ $app->log($this->log_prefix.'Fetching data from '.$this->fetch_url);
$vendor_page = $this->fetchPage('/all-app/'); //$vendor_page = $this->fetchPage('/'.$this->aps_version.'/');
preg_match_all("/\<a href=\"(.+)\/\" class=\"vendor\"/i", $vendor_page, $matches);
@@ -224,7 +232,12 @@
if(!$vendors) throw new Exception('Unable to fetch vendors. Aborting');
// Format all vendors for further processing (i.e. typo3.org -> /1.atom?vendor=typo3.org&pageSize=100
- array_walk($vendors, array($this, 'formatVendorCallback'));
+ //array_walk($vendors, array($this, 'formatVendorCallback'));
+ if(is_array($vendors)) {
+ foreach($vendors as $key => $array_item) {
+ $vendors[$key] = $this->formatVendorCallback($array_item);
+ }
+ }
// Process all vendors in chunks of 50 entries
$vendor_chunks = array_chunk($vendors, 50);
@@ -233,7 +246,7 @@
// Get all known apps from the database and the highest known version
// Note: A dirty hack is used for numerical sorting of the VARCHAR field Version: +0 -> cast
// A longer but typesafe way would be: ORDER BY CAST(REPLACE(Version, '.', '') AS UNSIGNED) DESC
- $existing_apps = $this->db->queryAllRecords("SELECT * FROM (
+ $existing_apps = $app->db->queryAllRecords("SELECT * FROM (
SELECT name AS Name, CONCAT(version, '-', CAST(`release` AS CHAR)) AS CurrentVersion
FROM aps_packages ORDER BY REPLACE(version, '.', '')+0 DESC, `release` DESC
) as Versions GROUP BY name");
@@ -270,9 +283,16 @@
// Find out a (possibly) existing package version
$ex_ver = '';
+ /*
array_walk($existing_apps,
create_function('$v, $k, $ex_ver', 'if($v["Name"] == "'.$app_name.'") $ex_ver = $v["CurrentVersion"];'), &$ex_ver);
-
+ */
+ if(is_array($existing_apps)) {
+ foreach($existing_apps as $k => $v) {
+ if($v["Name"] == $app_name) $ex_ver = $v["CurrentVersion"];
+ }
+ }
+
$new_ver = $app_version.'-'.$app_release;
$local_intf_folder = $this->interface_pkg_dir.'/'.$app_name.'-'.$new_ver.'.app.zip/';
@@ -290,6 +310,8 @@
$app_dl = parent::getXPathValue($sxe, "entry[position()=1]/link[@a:type='aps']/@href");
$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;
// Skip ASP.net packages because they can't be used at all
$asp_handler = parent::getXPathValue($sxe, '//aspnet:handler');
@@ -307,14 +329,14 @@
if(file_exists($old_folder)) $this->removeDirectory($old_folder);
/*
- $this->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_OUTDATED."' WHERE name = '".
- $this->db->quote($app_name)."' AND CONCAT(version, '-', CAST(`release` AS CHAR)) = '".
- $this->db->quote($ex_ver)."';");
+ $app->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_OUTDATED."' WHERE name = '".
+ $app->db->quote($app_name)."' AND CONCAT(version, '-', CAST(`release` AS CHAR)) = '".
+ $app->db->quote($ex_ver)."';");
*/
- $tmp = $this->db->queryOneRecord("SELECT id FROM aps_packages WHERE name = '".
- $this->db->quote($app_name)."' AND CONCAT(version, '-', CAST(`release` AS CHAR)) = '".
- $this->db->quote($ex_ver)."';");
- $this->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_OUTDATED, 'id', $tmp['id']);
+ $tmp = $app->db->queryOneRecord("SELECT id FROM aps_packages WHERE name = '".
+ $app->db->quote($app_name)."' AND CONCAT(version, '-', CAST(`release` AS CHAR)) = '".
+ $app->db->quote($ex_ver)."';");
+ $app->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_OUTDATED, 'id', $tmp['id']);
unset($tmp);
}
@@ -428,19 +450,19 @@
if($apps_to_dl_chunks[$i][$j]['filesize'] != 0 &&
$apps_to_dl_chunks[$i][$j]['filesize'] != filesize($apps_to_dl_chunks[$i][$j]['localtarget']))
{
- $this->app->log($this->log_prefix.' The filesize of the package "'.
+ $app->log($this->log_prefix.' The filesize of the package "'.
$apps_to_dl_chunks[$i][$j]['name'].'" is wrong. Download failure?', LOGLEVEL_WARN);
}
}
}
- $this->app->log($this->log_prefix.'Processed '.$apps_in_repo.
+ $app->log($this->log_prefix.'Processed '.$apps_in_repo.
' apps from the repo. Downloaded '.$apps_updated.
' updates, '.$apps_downloaded.' new apps');
}
catch(Exception $e)
{
- $this->app->log($this->log_prefix.$e->getMessage(), LOGLEVEL_ERROR);
+ $app->log($this->log_prefix.$e->getMessage(), LOGLEVEL_ERROR);
return false;
}
}
@@ -454,6 +476,8 @@
*/
public function parseFolderToDB()
{
+ global $app;
+
try
{
// This method must be used in server mode
@@ -473,15 +497,16 @@
// Get registered packages and mark non-existant packages with an error code to omit the install
$existing_packages = array();
- $path_query = $this->db->queryAllRecords('SELECT path AS Path FROM aps_packages;');
+ $path_query = $app->db->queryAllRecords('SELECT path AS Path FROM aps_packages;');
foreach($path_query as $path) $existing_packages[] = $path['Path'];
$diff = array_diff($existing_packages, $pkg_list);
- foreach($diff as $todelete)
- /*$this->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_ERROR_NOMETA."'
- WHERE path = '".$this->db->quote($todelete)."';");*/
- $tmp = $this->db->queryOneRecord("SELECT id FROM aps_packages WHERE path = '".$this->db->quote($todelete)."';");
- $this->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_ERROR_NOMETA, 'id', $tmp['id']);
+ foreach($diff as $todelete) {
+ /*$app->db->query("UPDATE aps_packages SET package_status = '".PACKAGE_ERROR_NOMETA."'
+ WHERE path = '".$app->db->quote($todelete)."';");*/
+ $tmp = $app->db->queryOneRecord("SELECT id FROM aps_packages WHERE path = '".$app->db->quote($todelete)."';");
+ $app->db->datalogUpdate('aps_packages', "package_status = ".PACKAGE_ERROR_NOMETA, 'id', $tmp['id']);
unset($tmp);
+ }
// Register all new packages
$new_packages = array_diff($pkg_list, $existing_packages);
@@ -491,7 +516,7 @@
$metafile = $this->interface_pkg_dir.'/'.$pkg.'/APP-META.xml';
if(!file_exists($metafile))
{
- $this->app->log($this->log_prefix.'Cannot read metadata from '.$pkg, LOGLEVEL_ERROR);
+ $app->log($this->log_prefix.'Cannot read metadata from '.$pkg, LOGLEVEL_ERROR);
continue;
}
@@ -508,25 +533,25 @@
$pkg_release = parent::getXPathValue($sxe, 'release');
/*
- $this->db->query("INSERT INTO `aps_packages`
+ $app->db->query("INSERT INTO `aps_packages`
(`path`, `name`, `category`, `version`, `release`, `package_status`) VALUES
- ('".$this->db->quote($pkg)."', '".$this->db->quote($pkg_name)."',
- '".$this->db->quote($pkg_category)."', '".$this->db->quote($pkg_version)."',
- ".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");");
+ ('".$app->db->quote($pkg)."', '".$app->db->quote($pkg_name)."',
+ '".$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_status`) VALUES
- ('".$this->db->quote($pkg)."', '".$this->db->quote($pkg_name)."',
- '".$this->db->quote($pkg_category)."', '".$this->db->quote($pkg_version)."',
- ".$this->db->quote($pkg_release).", ".PACKAGE_ENABLED.");";
+ $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->datalogInsert('aps_packages', $insert_data, 'id');
}
}
catch(Exception $e)
{
- $this->app->log($this->log_prefix.$e->getMessage(), LOGLEVEL_ERROR);
- $this->app->error($e->getMessage());
+ $app->log($this->log_prefix.$e->getMessage(), LOGLEVEL_ERROR);
+ $app->error($e->getMessage());
return false;
}
}
--
Gitblit v1.9.1