Commit 7ccaea08 authored by Aria's avatar Aria

changed naming of variables, old extracted files will be replaced

parent 969147bf
......@@ -48,7 +48,7 @@ class UpdateKelkooFeed extends Command
public function handle()
{
$this->deleteOldFeeds();
$this->deleteOldArchives();
$this->downloadNewFeeds();
if($this->checkMD5()) {
$this->extractFeedFiles();
......@@ -56,9 +56,9 @@ class UpdateKelkooFeed extends Command
}
private function deleteOldFeeds() {
$filesInDirectory = scandir($this->localFeedFilePath);
foreach ($filesInDirectory as $file) {
private function deleteOldArchives() {
$archivesInDirectory = scandir($this->localFeedFilePath);
foreach ($archivesInDirectory as $file) {
if(is_file($this->localFeedFilePath . "/" . $file)) {
unlink($this->localFeedFilePath . "/" . $file);
}
......@@ -96,8 +96,8 @@ class UpdateKelkooFeed extends Command
* Calculates MD5 values for the downloaded archives and verifies their integrity with the included "feeds.md5" file
*/
private function checkMD5() {
$filesInDirectory = scandir($this->localFeedFilePath);
$archiveFileMatches = preg_grep("/[\w\d]*Catalog[\S.]*\.xml\.gz/i", $filesInDirectory);
$archivesInDirectory = scandir($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");
......@@ -114,13 +114,22 @@ class UpdateKelkooFeed extends Command
}
private function extractFeedFiles() {
$filesInDirectory = scandir($this->localFeedFilePath);
$archiveFileMatches = preg_grep("/[\w\d]*Catalog[\S.]*\.xml\.gz/i", $filesInDirectory);
$archivesInDirectory = scandir($this->localFeedFilePath);
$archiveFileMatches = preg_grep("/[\w\d]*Catalog[\S.]*\.xml\.gz/i", $archivesInDirectory);
$oldFeedFilesInDirectory = scandir($this->localExtractedFilePath);
$file = fopen($this->localExtractedFilePath . $this->unzippedFileName . "_" . time() . ".xml", "w");
foreach ($archiveFileMatches as $archiveFile) {
$unzipped = gzdecode(file_get_contents($this->localFeedFilePath . $archiveFile));
fwrite($file, $unzipped);
}
fclose($file);
foreach ($oldFeedFilesInDirectory as $oldFeedFile) {
if(is_file($this->localExtractedFilePath . "/" . $oldFeedFile)) {
unlink($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