public function maintenanceCompress() { $perIteration = 100; $alreadyCompressedCounter = 0; $overallCounter = 0; $list = new Version\Listing(); $list->setCondition("date < " . (time() - 86400 * 30)); $list->setOrderKey("date"); $list->setOrder("DESC"); $list->setLimit($perIteration); $total = $list->getTotalCount(); $iterations = ceil($total / $perIteration); for ($i = 0; $i < $iterations; $i++) { Logger::debug("iteration " . ($i + 1) . " of " . $iterations); $list->setOffset($i * $perIteration); $versions = $list->load(); foreach ($versions as $version) { $overallCounter++; if (file_exists($version->getFilePath())) { gzcompressfile($version->getFilePath(), 9); @unlink($version->getFilePath()); $alreadyCompressedCounter = 0; Logger::debug("version compressed:" . $version->getFilePath()); } else { $alreadyCompressedCounter++; } if ($overallCounter % 10 == 0) { Logger::debug("Waiting 5 secs to not kill the server..."); sleep(5); } } \Pimcore::collectGarbage(); // check here how many already compressed versions we've found so far, if over 100 skip here // this is necessary to keep the load on the system low // is would be very unusual that older versions are not already compressed, so we assume that only new // versions need to be compressed, that's not perfect but a compromise we can (hopefully) live with. if ($alreadyCompressedCounter > 100) { Logger::debug("Over " . $alreadyCompressedCounter . " versions were already compressed before, it doesn't seem that there are still uncompressed versions in the past, skip..."); return; } } }