Add a few helper scripts

This commit is contained in:
patrick 2025-03-13 23:01:51 +00:00
parent 0d5541d3ae
commit 7bd3926176
2 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,49 @@
<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
require_once ('./data/config.inc.php');
$dsn = "mysql:host=db;dbname=$DBNAME;charset=utf8mb4";
$pdo = new PDO($dsn, $DBUSER, $DBPASS);
try {
//echo "SELECT DISTINCT CONCAT('ALTER TABLE ', TABLE_NAME,' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;') as queries FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$DBNAME' AND TABLE_TYPE='BASE TABLE' UNION SELECT DISTINCT CONCAT('ALTER TABLE ', C.TABLE_NAME, ' CHANGE ', C.COLUMN_NAME, ' ', C.COLUMN_NAME, ' ', C.COLUMN_TYPE, ' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;') as queries FROM INFORMATION_SCHEMA.COLUMNS as C LEFT JOIN INFORMATION_SCHEMA.TABLES as T ON C.TABLE_NAME = T.TABLE_NAME WHERE C.COLLATION_NAME is not null AND C.TABLE_SCHEMA='$DBNAME' AND T.TABLE_TYPE='BASE TABLE'";
$stmt = $pdo->prepare("SELECT DISTINCT CONCAT('ALTER TABLE ', TABLE_NAME,' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;') as queries FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$DBNAME' AND TABLE_TYPE='BASE TABLE' UNION SELECT DISTINCT CONCAT('ALTER TABLE ', C.TABLE_NAME, ' CHANGE ', C.COLUMN_NAME, ' ', C.COLUMN_NAME, ' ', C.COLUMN_TYPE, ' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;') as queries FROM INFORMATION_SCHEMA.COLUMNS as C LEFT JOIN INFORMATION_SCHEMA.TABLES as T ON C.TABLE_NAME = T.TABLE_NAME WHERE C.COLLATION_NAME is not null AND C.TABLE_SCHEMA='$DBNAME' AND T.TABLE_TYPE='BASE TABLE'");
$stmt->execute();
while ($r = $stmt->fetch(PDO::FETCH_OBJ)) {
foreach ($r as $query) {
print_r($r);
$stmt = $pdo->prepare($query);
$stmt->execute();
}
}
} catch (PDOException $exception) {
error_log('Err: ' . $exception);
}
?>

View File

@ -0,0 +1,106 @@
<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
require_once ('./data/config.inc.php');
$API_URL="https://signatures.algolibre.io/api";
$TEMPLATE_ID=7;
$dsn = "mysql:host=db;dbname=$DBNAME;charset=utf8mb4";
$pdo = new PDO($dsn, $DBUSER, $DBPASS);
$pagination = -1;
$curl = curl_init();
$completed = [];
do {
$SIGNATURES_MAX = 100;
$url = "$API_URL/submissions?template_id=$TEMPLATE_ID&status=completed&limit=$SIGNATURES_MAX";
if ($pagination != -1) {
$url = "$API_URL/submissions?template_id=$TEMPLATE_ID&status=completed&limit=$SIGNATURES_MAX&after=" . $pagination;
}
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'X-Auth-Token: baEUbT1iLsNdBDSWpNqvxoTCDshJ6a6D8YDCsjMxAKF'
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
$converted = mb_convert_encoding($response, 'UTF-8');
$data = json_decode($converted);
foreach ($data->data as $submissions) {
foreach ($submissions->submitters as $submitter) {
if ($submitter->role == "Student 1" && $submissions->archived_at == null) {
$completed[] = $submitter->email;
}
}
}
$pagination = $data->pagination->next;
}
} while ($pagination > 0);
foreach ($completed as $student) {
try {
$stmt = $pdo->prepare("UPDATE registrations set status='paymentpending' where email=? and status != 'complete'");
$stmt->execute([$student]);
if ($stmt->rowCount() == 0) {
error_log("No update for: " . $student);
}
} catch (PDOException $exception) {
error_log("Err: " . $student . ": " . $exception);
}
}
curl_close($curl);
?>