<commit_before><?php
namespace Grav\Common\Backup;

use Grav\Common\GravTrait;
use Grav\Common\Filesystem\Folder;

/**
 * The ZipBackup class lets you create simple zip-backups of a grav site
 *
 * @author RocketTheme
 * @license MIT
 */
class ZipBackup
{
    use GravTrait;

    public static function backup($destination = null, callable $messager = null)
    {
        if (!$destination) {
            $destination = self::getGrav()['locator']->findResource('cache://', true);
            $destination = $destination . DS . 'tmp/Grav-' . uniqid();
            Folder::mkdir($destination);
        }

        $name = basename(GRAV_ROOT);

        if (is_dir($destination)) {
            $date = date('YmdHis', time());
            $filename = $name . '-' . $date . '.zip';
            $destination = rtrim($destination, DS) . DS . $filename;
        }

        $messager && $messager([
            'type' => 'message',
            'level' => 'info',
            'message' => 'Creating new Backup "' . $destination . '"'
        ]);
        $messager && $messager([
            'type' => 'message',
            'level' => 'info',
            'message' => ''
        ]);

        $zip = new \ZipArchive();
        $zip->open($destination, \ZipArchive::CREATE);
        $zip->addEmptyDir($name);

        static::folderToZip(GRAV_ROOT, $zip, strlen(rtrim(GRAV_ROOT, DS) . DS), $messager);

        $messager && $messager([
            'type' => 'progress',
            'percentage' => false,
            'complete' => true<commit_msg>use site name for backup archive name<commit_after><?php
namespace Grav\Common\Backup;

use Grav\Common\GravTrait;
use Grav\Common\Filesystem\Folder;

/**
 * The ZipBackup class lets you create simple zip-backups of a grav site
 *
 * @author RocketTheme
 * @license MIT
 */
class ZipBackup
{
    use GravTrait;

    public static function backup($destination = null, callable $messager = null)
    {
        if (!$destination) {
            $destination = self::getGrav()['locator']->findResource('cache://', true);
            $destination = $destination . DS . 'tmp/Grav-' . uniqid();
            Folder::mkdir($destination);
        }

        $name = self::getGrav()['config']->get('site.title', basename(GRAV_ROOT));

        if (is_dir($destination)) {
            $date = date('YmdHis', time());
            $filename = $name . '-' . $date . '.zip';
            $destination = rtrim($destination, DS) . DS . $filename;
        }

        $messager && $messager([
            'type' => 'message',
            'level' => 'info',
            'message' => 'Creating new Backup "' . $destination . '"'
        ]);
        $messager && $messager([
            'type' => 'message',
            'level' => 'info',
            'message' => ''
        ]);

        $zip = new \ZipArchive();
        $zip->open($destination, \ZipArchive::CREATE);
        $zip->addEmptyDir($name);

        static::folderToZip(GRAV_ROOT, $zip, strlen(rtrim(GRAV_ROOT, DS) . DS), $messager);

        $messager && $messager([
            'type' => 'progress',
            'percentage' => false,
            'complete' => true
{'fraction_non_alphanumeric': 0.1683673469387755, 'fraction_numerical': 0.0, 'mean_word_length': 2.1121031746031744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7381309', 'n_tokens_mistral': 975, 'n_tokens_neox': 917, 'n_words': 206}