Skip to content

Commit

Permalink
Update upgrade1.3.5to1.4.0.php
Browse files Browse the repository at this point in the history
lint sql column names, update messages, make sure to only update if necessary. and also update builds' loadertype.
  • Loading branch information
cowpod committed Oct 29, 2024
1 parent 18c02a6 commit 5c0388f
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions functions/upgrade1.3.5to1.4.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
$db=new Db;
$db->connect();

echo "<hr/>Altering table mods<br/>";
echo "<hr/>Altering table columns<br/>";

// 1.4.0: mod version ranges
// naturally, we assume user is using mysql.
$addtype1=$db->execute("ALTER TABLE `mods` ADD COLUMN `loadertype` VARCHAR(32);");
$addtype2=$db->execute("ALTER TABLE `builds` ADD COLUMN `loadertype` VARCHAR(32);");
$addtype1=$db->execute("ALTER TABLE mods ADD COLUMN loadertype VARCHAR(32);");
$addtype2=$db->execute("ALTER TABLE builds ADD COLUMN loadertype VARCHAR(32);");

if (!$addtype||!$addtype) {
die("Couldn't add new columns loadertype to table `mods`! Are we already upgraded? <a href='/'>Click here to return to index</a>.");
die("Couldn't add new columns loadertype to table mods! Are we already upgraded? <a href='/'>Click here to return to index</a>.");
}

mkdir('../upgrade_work');
Expand All @@ -28,7 +28,7 @@
require('modInfo.php');
$mi = new modInfo();

$mods=$db->query("SELECT id,filename FROM `mods` WHERE type='mod'");
$mods=$db->query("SELECT id,filename FROM mods WHERE type='mod'");

foreach ($mods as $mod) {
$zip = new ZipArchive;
Expand Down Expand Up @@ -58,15 +58,15 @@
$modltq = $db->query("SELECT loadertype from mods where id = ".$mod['id']);
if ($modltq) {
if (sizeof($modltq)==1 && $modltq[0]['loadertype']===$loader_type) {
echo 'mod id='.$mod['id'].' name='.$mod['name'].' already has loadertype='.$loader_type.'. skipping.<br/>';
echo 'Skipping mod id='.$mod['id'].' name='.$mod['name'].' already has loadertype='.$loader_type.'<br/>';
continue;
}
}

$updatemodx = $db->execute("UPDATE mods SET loadertype = '".$loader_type."' where id = ".$mod['id']);

if ($updatemodx) {
echo 'mod id='.$mod['id'].', name='.$mod['name'].' updated, loadertype='.$loader_type.".<br/>";
echo 'Updated mod id='.$mod['id'].', name='.$mod['name'].', loadertype='.$loader_type.".<br/>";
} else {
echo 'failed to update mod id='.$mod['id'].' name='.$mod['name'];
}
Expand All @@ -81,16 +81,58 @@

echo "<hr/>Updating modloader entries<br/>";

$forges=$db->query("SELECT id,filename FROM `mods` WHERE type='forge'");
$forges=$db->query("SELECT id,filename,loadertype FROM mods WHERE type='forge'");
foreach ($forges as $forge) {
if (str_starts_with($forge['filename'], 'forge-')) {
$db->execute("UPDATE mods SET loadertype='forge' WHERE id='".$forge['id']."'");
}
else if (str_starts_with($forge['filename'], 'neoforge-')) {
$db->execute("UPDATE mods SET loadertype='neoforge' WHERE id='".$forge['id']."'");
if (empty($forge['loadertype'])) {
if (str_starts_with($forge['filename'], 'forge-')) {
$db->execute("UPDATE mods SET loadertype='forge' WHERE id='".$forge['id']."'");
}
else if (str_starts_with($forge['filename'], 'neoforge-')) {
$db->execute("UPDATE mods SET loadertype='neoforge' WHERE id='".$forge['id']."'");
}
else if (str_starts_with($forge['filename'], 'fabric-')) {
$db->execute("UPDATE mods SET loadertype='fabric' WHERE id='".$forge['id']."'");
} else {
error_log("unknown filename ".$forge['filename']);
echo "Unknown filename ".$forge['filename'];
continue; // idk what this is
}
echo "Updated ".$forge['filename']."<br/>";
} else {
echo "Skipping ".$forge['filename']." as it already has loadertype=".$forge['loadertype']."<br/>";
}
else if (str_starts_with($forge['filename'], 'fabric-')) {
$db->execute("UPDATE mods SET loadertype='fabric' WHERE id='".$forge['id']."'");
}

echo "<hr/>Updating builds entries<br/>";

$builds=$db->query("SELECT id,name,mods,loadertype FROM builds");

foreach ($builds as $build) {
if (empty($build['loadertype'])) {
// now get the mod details
$mod_loadertype="";
foreach (explode(",", $build['mods']) as $id) {
$mod_loadertype = $db->query("SELECT id,loadertype FROM mods WHERE id = ".$id." AND type='forge'");
if ($mod_loadertype===FALSE || empty($mod_loadertype) || sizeof($mod_loadertype)!==1) {
continue;
}
// at this point we have a forge entry
$mod_loadertype=$mod_loadertype[0]['loadertype'];
break;
}
if (!empty($mod_loadertype)) {
$updateres = $db->execute("UPDATE builds SET loadertype = '".$mod_loadertype."' WHERE id = ".$build['id']);

if ($updateres===TRUE) {
echo "Updated ".$build['name']." = '".$mod_loadertype."'<br/>";
} else {
echo "Failed to update ".$build['name']."<br/>";
}
} else {
echo "Failed to update ".$build['name']."<br/>";
}
} else {
echo "Build ".$build['name']." already has loadertype=".$build['loadertype']."<br/>";
}
}

Expand Down

0 comments on commit 5c0388f

Please sign in to comment.