From 7bd39261765c0c96b54a19534e5c20022fe79edd Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 13 Mar 2025 23:01:51 +0000 Subject: [PATCH] Add a few helper scripts --- scripts/update_encoding.php | 49 ++++++++++++++++ scripts/update_signatures.php | 106 ++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 scripts/update_encoding.php create mode 100644 scripts/update_signatures.php diff --git a/scripts/update_encoding.php b/scripts/update_encoding.php new file mode 100644 index 00000000..3aa55059 --- /dev/null +++ b/scripts/update_encoding.php @@ -0,0 +1,49 @@ + + * Copyright (C) 2005 James Grant + * Copyright (C) 2024 AlgoLibre Inc. + * + * 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); +} +?> \ No newline at end of file diff --git a/scripts/update_signatures.php b/scripts/update_signatures.php new file mode 100644 index 00000000..da6fc896 --- /dev/null +++ b/scripts/update_signatures.php @@ -0,0 +1,106 @@ + + * Copyright (C) 2005 James Grant + * Copyright (C) 2024 AlgoLibre Inc. + * + * 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); + +?> \ No newline at end of file