function commerce_smart_importer_cron in Commerce Smart Importer 8
Implements hook_cron().
File
- ./
commerce_smart_importer.module, line 30 - Commerce Smart Importer module file.
Code
function commerce_smart_importer_cron() {
if (!is_dir(CommerceSmartImporterConstants::TEMP_DIR)) {
return;
}
$current_timestamp = new DrupalDateTime();
$current_timestamp = $current_timestamp
->getTimestamp();
$dir_data = scandir(CommerceSmartImporterConstants::TEMP_DIR);
foreach ($dir_data as $data) {
if (is_file(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data)) {
$last_modification = filemtime(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data);
if ($current_timestamp - $last_modification > 86400) {
unlink(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data);
}
}
elseif (is_dir(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data)) {
$last_modification = stat(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data);
$last_modification = $last_modification['mtime'];
if ($current_timestamp - $last_modification > 86400) {
$dir = CommerceSmartImporterConstants::TEMP_DIR . '/' . $data;
$import_content = scandir($dir);
foreach ($import_content as $files) {
if (is_file($dir . '/' . $files)) {
unlink($dir . '/' . $files);
}
}
}
if (count(scandir(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data)) == 2) {
rmdir(CommerceSmartImporterConstants::TEMP_DIR . '/' . $data);
}
}
}
}