Esempio n. 1
0
/**
 * Truncate the exports directory, delete old files.
 *
 * @param int $max
 */
function truncate_exports($max)
{
    $max = absint($max);
    $dir = \PressBooks\Export\Export::getExportFolder();
    $files = group_exports();
    $i = 1;
    foreach ($files as $date => $exports) {
        if ($i > $max) {
            foreach ($exports as $export) {
                $export = realpath($dir . $export);
                unlink($export);
            }
        }
        ++$i;
    }
}
Esempio n. 2
0
/**
 * Truncate the exports directory, delete old files.
 *
 * @param int $max
 * @param string $dir fullpath to the Exports fo
 * lder. (optional)
 */
function truncate_exports($max, $dir = null)
{
    if (!$dir) {
        $dir = \PressBooks\Modules\Export\Export::getExportFolder();
    } else {
        $dir = rtrim($dir, '/') . '/';
    }
    $max = absint($max);
    $files = group_exports($dir);
    $i = 1;
    foreach ($files as $date => $exports) {
        if ($i > $max) {
            foreach ($exports as $export) {
                $export = realpath($dir . $export);
                WP_Filesystem();
                unlink($export);
            }
        }
        ++$i;
    }
}