<commit_before><?php
declare(strict_types = 1);

namespace qnd;

use DOMDocument;
use Exception;
use RuntimeException;
use XSLTProcessor;

/**
 * Import project from ZIP file
 *
 * @todo Import homepage?!
 *
 * @param string $name
 * @param string $file
 *
 * @return bool
 */
function import_zip(string $name, string $file): bool
{
    $path = path('tmp', uniqid('import', true));
    $toc = $path . '/' . data('app', 'import.toc');

    try {
        unzip($file, $path);
    } catch (Exception $e) {
        message($e->getMessage());
        return false;
    }

    if (!is_file($toc)) {
        message(_('File %s not found', basename($toc)));
        return false;
    }

    $trans = db_trans(
        function () use ($name, $path, $toc) {
            $csv = csv_unserialize(file_get_contents($toc), ['keys' => ['pos', 'name', 'file']]);

            if (!$project = import_project($name)) {
                throw new RuntimeException(_('Import error'));
            }

            // Copy media files
            $asset = path('asset', (string) $project['id']);
            file_copy($path . '/media', $asset . '/media');

            // Create new page
            foreach ($csv as $data) {
                $file = $data['file'] ? $path . '/' . $data['file'] : null;

                if (!import_page('page', $project['id'], $data['name'], $file)) {
                    file_delete($asset);
                    throw new RuntimeException(_('Import error'));
                }
            }
        }
    );
    file_delete($path);

    return $trans;
}
<commit_msg>Remove comments<commit_after><?php
declare(strict_types = 1);

namespace qnd;

use DOMDocument;
use Exception;
use RuntimeException;
use XSLTProcessor;

/**
 * Import project from ZIP file
 *
 * @todo Import homepage?!
 *
 * @param string $name
 * @param string $file
 *
 * @return bool
 */
function import_zip(string $name, string $file): bool
{
    $path = path('tmp', uniqid('import', true));
    $toc = $path . '/' . data('app', 'import.toc');

    try {
        unzip($file, $path);
    } catch (Exception $e) {
        message($e->getMessage());
        return false;
    }

    if (!is_file($toc)) {
        message(_('File %s not found', basename($toc)));
        return false;
    }

    $trans = db_trans(
        function () use ($name, $path, $toc) {
            $csv = csv_unserialize(file_get_contents($toc), ['keys' => ['pos', 'name', 'file']]);

            if (!$project = import_project($name)) {
                throw new RuntimeException(_('Import error'));
            }

            $asset = path('asset', (string) $project['id']);
            file_copy($path . '/media', $asset . '/media');

            foreach ($csv as $data) {
                $file = $data['file'] ? $path . '/' . $data['file'] : null;

                if (!import_page('page', $project['id'], $data['name'], $file)) {
                    file_delete($asset);
                    throw new RuntimeException(_('Import error'));
                }
            }
        }
    );
    file_delete($path);

    return $trans;
}

{'fraction_non_alphanumeric': 0.17599482368165642, 'fraction_numerical': 0.0006470397929472663, 'mean_word_length': 2.0981963927855714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '295470', 'n_tokens_mistral': 952, 'n_tokens_neox': 909, 'n_words': 229}