2016-08-10 18:03:06 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @Author: printempw
|
|
|
|
* @Date: 2016-08-09 21:44:13
|
|
|
|
* @Last Modified by: printempw
|
2016-08-20 21:08:46 +08:00
|
|
|
* @Last Modified time: 2016-08-20 20:49:37
|
2016-08-10 18:03:06 +08:00
|
|
|
*
|
|
|
|
* There are still some coupling relationships here but,
|
|
|
|
* Just let it go :)
|
|
|
|
*/
|
|
|
|
|
2016-08-19 23:09:32 +08:00
|
|
|
if (!defined('BASE_DIR')) exit('Permission denied.');
|
|
|
|
|
2016-08-10 18:03:06 +08:00
|
|
|
$v2_table_name = $_POST['v2_table_name'];
|
|
|
|
$v3_table_name = Config::getDbConfig()['prefix']."textures";
|
|
|
|
|
|
|
|
$imported = 0;
|
|
|
|
$duplicated = 0;
|
|
|
|
|
|
|
|
// use db helper instead of fat ORM
|
2016-08-14 08:31:07 +08:00
|
|
|
$db = Database::table($v2_table_name, true);
|
2016-08-10 18:03:06 +08:00
|
|
|
|
|
|
|
$steps = ceil($db->getRecordNum() / 250);
|
|
|
|
|
2016-08-20 21:08:46 +08:00
|
|
|
$public = isset($_POST['import_as_private']) ? '0' : '1';
|
2016-08-19 23:09:32 +08:00
|
|
|
|
2016-08-20 21:08:46 +08:00
|
|
|
// chunked (optionally)
|
2016-08-10 18:03:06 +08:00
|
|
|
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']);
|
|
|
|
|
2016-08-20 21:08:46 +08:00
|
|
|
$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)) {
|
|
|
|
$db->insert([
|
|
|
|
'name' => $name,
|
|
|
|
'type' => $model,
|
|
|
|
'likes' => 0,
|
|
|
|
'hash' => $row["hash_$model"],
|
|
|
|
'size' => Storage::size(BASE_DIR.'/textures/'.$row["hash_$model"]),
|
|
|
|
'uploader' => $_POST['uploader_uid'],
|
|
|
|
'public' => $public,
|
|
|
|
'upload_at' => Utils::getTimeFormatted()
|
|
|
|
], $v3_table_name);
|
|
|
|
|
|
|
|
$imported++;
|
|
|
|
// echo $row['hash_steve']." saved. <br />";
|
|
|
|
} else {
|
|
|
|
$duplicated++;
|
|
|
|
// echo $row['hash_steve']." duplicated. <br />";
|
|
|
|
}
|
2016-08-10 18:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'imported' => $imported,
|
|
|
|
'duplicated' => $duplicated
|
|
|
|
];
|