summaryrefslogtreecommitdiff
path: root/public/config/init-setup-db.php
diff options
context:
space:
mode:
authorGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
committerGeo Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2026-07-12 15:51:52 +0300
commit02608271bb2a9f3a65ed536984d306ee14b48e34 (patch)
tree3f23ec48a694ec014e845c4f70d9b5f1c065403c /public/config/init-setup-db.php
downloadkalassa-02608271bb2a9f3a65ed536984d306ee14b48e34.tar.gz
kalassa-02608271bb2a9f3a65ed536984d306ee14b48e34.tar.bz2
kalassa-02608271bb2a9f3a65ed536984d306ee14b48e34.zip
initialize repository; add docker config; migrate configuration to new specsHEADmaster
Diffstat (limited to 'public/config/init-setup-db.php')
-rw-r--r--public/config/init-setup-db.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/public/config/init-setup-db.php b/public/config/init-setup-db.php
new file mode 100644
index 0000000..848d878
--- /dev/null
+++ b/public/config/init-setup-db.php
@@ -0,0 +1,66 @@
+<?php
+// THIS SCRIPTS RUNS SOME LOW LEVEL OPERATIONS
+// AND SHALL BE USED BY WEB-ADMINISTRATOR ONLY
+////////////////////////////////////////////////////////////////////////////////
+//
+// This script may used to
+// -- * init database (TODO: do=init-db)
+// -- * setup sub-tables to handle items identity per CCODE (do=init-idx)
+// -- * re-index items into sub-tables (TODO: do=re-idx)
+// -- * re-calculate (TODO: do=re-calc[&idx=##_#])
+// -----------------------------------------------------------------------------
+//
+// Call:
+// %domain%%path%/setup-db.php[?pin=id][&do=action][&idx=##_##]
+// ex.
+// %domain%%path%/setup-db.php : return a pin (TTL = 1min)
+// %domain%%path%/setup-db.php
+
+// 0. INITIALIZATION
+// -----------------------------------------------------------------------------
+// Load parametres (for db-connection)
+// Load main Json for CCODES
+// Init anything needed before starting the main script
+////////////////////////////////////////////////////////////////////////////////
+
+include("parametres.php");
+$ccodeJSON = file_get_contents('ccode.json');
+$ccodeARRAY = json_decode($ccodeJSON);
+
+// an [on|off] line of code to prevent running the script accidentaly
+// -----------------------------------------------------------------------------
+echo "remove a line of code to run"; die();
+
+// init database connection
+// -----------------------------------------------------------------------------
+$_dbc = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DBMS);
+if ($_dbc->connect_errno) {
+ echo "Database connection failed; Please try in a few minutes. ";
+ if (TESTING) echo $_dbc->connect_error;
+ $_dbc->close(); die();
+}
+$_dbc->set_charset("utf8");
+
+// parse behaviour ($_GET) arguments
+//
+// BUILD indexing tables for all ccodes
+foreach ($ccodeARRAY as $key => $val) {
+
+ $_Table = "tt_". $val->idx;
+
+ $_stm = $_dbc->prepare("DROP TABLE IF EXISTS {$_Table}");
+ $_stm->execute(); // execute query
+ $_stm->close();
+
+ // prepare statemet
+ $_stm = $_dbc->prepare("CREATE TABLE {$_Table} LIKE template");
+ $_stm->execute(); // execute query
+ $_stm->close();
+
+ // Should you re-index tables? run the following
+
+ // INSERT INTO {$_Table} (id) SELECT id FROM items WHERE ccode = ? ORDER BY id
+
+}
+
+echo "Tables are ready";