Commit 85475d75 authored by Aria's avatar Aria

replaced full path specification with usage of config_path()

parent 3f336783
......@@ -23,12 +23,12 @@ class UpdateKelkooFeed extends Command
/**
*
*/
protected $url = "ftpkelkoo.kelkoo.net";
protected $port = 21;
protected $remoteFilePath = "/catalog/de/";
protected $localFeedFilePath = "config/KelkooFeeds/";
protected $localExtractedFilePath = "config/KelkooFeeds/ExtractedFeeds/";
protected $unzippedFileName = "Catalogfeed_full";
protected $url = "ftpkelkoo.kelkoo.net";
protected $port = 21;
protected $remoteFilePath = "/catalog/de/";
protected $localFeedFilePath = "/KelkooFeeds/";
protected $localExtractedFilePath = "/KelkooFeeds/ExtractedFeeds/";
protected $unzippedFileName = "Catalogfeed_full";
/**
* Create a new command instance.
......@@ -57,10 +57,10 @@ class UpdateKelkooFeed extends Command
private function deleteOldArchives() {
$archivesInDirectory = scandir($this->localFeedFilePath);
$archivesInDirectory = scandir(config_path() . $this->localFeedFilePath);
foreach ($archivesInDirectory as $file) {
if(is_file($this->localFeedFilePath . "/" . $file)) {
unlink($this->localFeedFilePath . "/" . $file);
if(is_file(config_path() . $this->localFeedFilePath . "/" . $file)) {
unlink(config_path() . $this->localFeedFilePath . "/" . $file);
}
}
}
......@@ -70,18 +70,18 @@ class UpdateKelkooFeed extends Command
mkdir('config/KelkooFeeds', 0777, true);
}
$connection = ftp_connect($this->url, $this->port);
if(!$connection) {
if($connection === FALSE) {
Log::error("Could not connect to $this->url");
return;
} else {
if(ftp_login($connection, env("kelkoo_username"), env("kelkoo_pass"))) {
$contents = ftp_nlist($connection, $this->remoteFilePath);
foreach ($contents as $content) {
if(ftp_get($connection, $this->localFeedFilePath . basename($content) , $this->remoteFilePath . basename($content) , FTP_BINARY)) {
echo "File transfer successful - ". $this->localFeedFilePath . basename($content) . "\n";
if(ftp_get($connection, config_path() . $this->localFeedFilePath . basename($content) , $this->remoteFilePath . basename($content) , FTP_BINARY)) {
echo "File transfer successful - ". config_path() . $this->localFeedFilePath . basename($content) . "\n";
} else {
echo "There was an error while downloading $this->localFeedFilePath" . basename($content) . "\n";
Log::error("Error while downloading $this->localFeedFilePath" . basename($content) . "\n");
echo "There was an error while downloading config_path() . $this->localFeedFilePath" . basename($content) . "\n";
Log::error("Error while downloading config_path() . $this->localFeedFilePath" . basename($content) . "\n");
return;
}
}
......@@ -96,11 +96,11 @@ class UpdateKelkooFeed extends Command
* Calculates MD5 values for the downloaded archives and verifies their integrity with the included "feeds.md5" file
*/
private function checkMD5() {
$archivesInDirectory = scandir($this->localFeedFilePath);
$archivesInDirectory = scandir(config_path() . $this->localFeedFilePath);
$archiveFileMatches = preg_grep("/[\w\d]*Catalog[\S.]*\.xml\.gz/i", $archivesInDirectory);
foreach ($archiveFileMatches as $archiveFile) {
$feed_md5 = md5_file($this->localFeedFilePath . "/" . $archiveFile);
$md5_file_content = file_get_contents($this->localFeedFilePath . "feeds.md5");
$feed_md5 = md5_file(config_path() . $this->localFeedFilePath . "/" . $archiveFile);
$md5_file_content = file_get_contents(config_path() . $this->localFeedFilePath . "feeds.md5");
if($md5_file_content === false) {
Log:error("Could not find \"feeds.md5\" file");
return false;
......@@ -117,21 +117,21 @@ class UpdateKelkooFeed extends Command
* Extracts the previously downloaded archives into one .xml file and after that deletes the old previous one
*/
private function extractReplaceFeedFiles() {
$archivesInDirectory = scandir($this->localFeedFilePath);
$archivesInDirectory = scandir(config_path() . $this->localFeedFilePath);
$archiveFileMatches = preg_grep("/[\w\d]*Catalog[\S.]*\.xml\.gz/i", $archivesInDirectory);
$oldFeedFilesInDirectory = scandir($this->localExtractedFilePath);
$oldFeedFilesInDirectory = scandir(config_path() . $this->localExtractedFilePath);
$file = fopen($this->localExtractedFilePath . $this->unzippedFileName . "_" . time() . ".xml", "w");
$file = fopen(config_path() . $this->localExtractedFilePath . $this->unzippedFileName . "_" . time() . ".xml", "w");
foreach ($archiveFileMatches as $archiveFile) {
$unzipped = gzdecode(file_get_contents($this->localFeedFilePath . $archiveFile));
$unzipped = gzdecode(file_get_contents(config_path() . $this->localFeedFilePath . $archiveFile));
fwrite($file, $unzipped);
}
fclose($file);
foreach ($oldFeedFilesInDirectory as $oldFeedFile) {
if(is_file($this->localExtractedFilePath . "/" . $oldFeedFile)) {
unlink($this->localExtractedFilePath . "/" . $oldFeedFile);
if(is_file(config_path() . $this->localExtractedFilePath . "/" . $oldFeedFile)) {
unlink(config_path() . $this->localExtractedFilePath . "/" . $oldFeedFile);
}
}
}
......
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