1<?php
2require '../config.php';
3require '../engine/database/connect.php';
4?>
5
6<h1>Gesior and Modern shop points to Znote AAC shop points</h1>
7<p>Convert donation/shop points from previous Gesior/Modern installation to Znote AAC:</p>
8<?php
9 $accounts = db()->fetchAll("SELECT `id`, `premium_points` FROM `accounts` WHERE `premium_points` > 0;");
10 $accountids = array();
11 foreach ($accounts as $acc) $accountids[] = $acc['id'];
12
13 if ($accounts !== false) echo "<p>Detected: ". count($accounts) ." accounts who have points in old system.</p>";
14 else die("<h1>All accounts already converted. :)</h1>");
15
16 $placeholders = implode(',', array_fill(0, count($accountids), '?'));
17 $znote_accounts = db()->fetchAll("SELECT `account_id`, `points` FROM `znote_accounts` WHERE `account_id` IN ($placeholders);", $accountids);
18
19 if (count($accounts) !== count($znote_accounts)) die("<h1><font color='red'>Failed to syncronize accounts. You need to convert all accounts to Znote AAC first!</font></h1>");
20
21 // Order old accounts by id.
22 $idaccounts = array();
23 foreach ($accounts as $acc) {
24 $idaccounts[$acc['id']] = $acc['premium_points'];
25 }
26 foreach ($znote_accounts as $acc) {
27 db()->execute("UPDATE `znote_accounts` SET `points` = ? WHERE `account_id` = ? LIMIT 1;", [$acc['points'] + $idaccounts[$acc['account_id']], $acc['account_id']]);
28 }
29 db()->execute("UPDATE `accounts` SET `premium_points` = 0;");
30
31 echo "<h1><font color='green'>Successfully converted all points!</font></h1>";
32?>