summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/class/table.class.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/class/table.class.php b/app/class/table.class.php
index 62f95d3..0edff9d 100644
--- a/app/class/table.class.php
+++ b/app/class/table.class.php
@@ -168,6 +168,45 @@ abstract class table
$query = "DELETE FROM views WHERE guid = '" . $guid . "' OR viewer = '" . $guid . "'";
$this->db->query($query);
}
+
+ /*
+ * Get a random sha256 blob, returned as a hexadecimal string
+ */
+ public function getBlob() : string
+ {
+ return hash("sha256", openssl_random_pseudo_bytes(64));
+ }
+
+ /*
+ * Get current timestamp as a string for object database purposes
+ */
+ private function getCurrentTimestamp() : string
+ {
+ $query = "SELECT now() AS stamp";
+ $res = $this->db->query($query);
+ return $res[0]['stamp'];
+ }
+
+ /*
+ * Check whether the given GUID exists
+ */
+ private function isGUID(string $guid) : bool
+ {
+ $guid = $this->db->esc($guid);
+ $query = "SELECT guid FROM objects WHERE guid = '" . $guid . "'";
+ $res = $this->db->query($query);
+ return count($res) > 0;
+ }
+
+ /*
+ * Get a new, unique GUID for a new system object
+ */
+ private function getNewGUID() : string
+ {
+ do $guid = substr($this->getBlob(), 0, 8);
+ while ($this->isGUID($guid));
+ return $guid;
+ }
}
?>