getRecordNum() / 250);
$public = isset($_POST['import_as_private']) ? '0' : '1';
// chunked (optionally)
for ($i = 0; $i <= $steps; $i++) {
$start = $i * 250;
$sql = "SELECT * FROM `$v2_table_name` ORDER BY `uid` LIMIT $start, 250";
$result = $db->query($sql);
while ($row = $result->fetch_array()) {
// compile patterns
$name = str_replace('{username}', $row['username'], $_POST['texture_name_pattern']);
$models = ['steve', 'alex', 'cape'];
foreach ($models as $model) {
if ($row['hash_steve'] != "") {
$name = str_replace('{model}', $model, $name);
if (!$db->has('hash', $row["hash_$model"], $v3_table_name)) {
// file size in bytes
$size = Storage::disk('textures')->has($row["hash_$model"]) ? Storage::disk('textures')->size($row["hash_$model"]) : 0;
$db->insert([
'name' => $name,
'type' => $model,
'likes' => 0,
'hash' => $row["hash_$model"],
'size' => ceil($size / 1024),
'uploader' => $_POST['uploader_uid'],
'public' => $public,
'upload_at' => Utils::getTimeFormatted()
], $v3_table_name);
$imported++;
// echo $row['hash_steve']." saved.
";
} else {
$duplicated++;
// echo $row['hash_steve']." duplicated.
";
}
}
}
}
}
return [
'imported' => $imported,
'duplicated' => $duplicated
];