]> git.mxchange.org Git - friendica.git/commitdiff
"cascade" for "post-engagement" / fixes for "report" definition
authorMichael <heluecht@pirati.ca>
Sun, 10 Sep 2023 03:47:06 +0000 (03:47 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 10 Sep 2023 03:47:06 +0000 (03:47 +0000)
database.sql
doc/database/db_report.md
src/Database/DBA.php
src/Database/DBStructure.php
static/dbstructure.config.php

index 7da771e0ead0309aaec1f05b2a4218ca354e2e29..6a7cb50e2ca7210cd9f754d8e50cd65d09df66c5 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2023.09-dev (Giant Rhubarb)
--- DB_UPDATE_VERSION 1531
+-- DB_UPDATE_VERSION 1532
 -- ------------------------------------------
 
 
@@ -1316,7 +1316,7 @@ CREATE TABLE IF NOT EXISTS `post-engagement` (
         INDEX `owner-id` (`owner-id`),
         INDEX `created` (`created`),
        FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
-       FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
+       FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Engagement data per post';
 
 --
@@ -1741,7 +1741,7 @@ CREATE TABLE IF NOT EXISTS `report` (
        `assigned-uid` mediumint unsigned COMMENT 'Assigned moderator user',
        `status` tinyint unsigned NOT NULL COMMENT 'Status of the report, one of Entity\Report::STATUS_*',
        `resolution` tinyint unsigned COMMENT 'Resolution of the report, one of Entity\Report::RESOLUTION_*',
-       `created` datetime(6) NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
+       `created` datetime(6) NOT NULL DEFAULT '0001-01-01 00:00:00.000000' COMMENT '',
        `edited` datetime(6) COMMENT 'Last time the report has been edited',
         PRIMARY KEY(`id`),
         INDEX `uid` (`uid`),
index c2890e25a917221616234c55c654a266c519f4bd..cae4a2f33b20883f991e03ce479e11fbe5dbb0af 100644 (file)
@@ -6,24 +6,24 @@ Table report
 Fields
 ------
 
-| Field           | Description                                                  | Type               | Null | Key | Default             | Extra          |
-| --------------- | ------------------------------------------------------------ | ------------------ | ---- | --- | ------------------- | -------------- |
-| id              | sequential ID                                                | int unsigned       | NO   | PRI | NULL                | auto_increment |
-| uid             | Reporting user                                               | mediumint unsigned | YES  |     | NULL                |                |
-| reporter-id     | Reporting contact                                            | int unsigned       | YES  |     | NULL                |                |
-| cid             | Reported contact                                             | int unsigned       | NO   |     | NULL                |                |
-| gsid            | Reported contact server                                      | int unsigned       | YES  |     | NULL                |                |
-| comment         | Report                                                       | text               | YES  |     | NULL                |                |
-| category-id     | Report category, one of Entity\Report::CATEGORY_*            | int unsigned       | NO   |     | 1                   |                |
-| forward         | Forward the report to the remote server                      | boolean            | YES  |     | NULL                |                |
-| public-remarks  | Remarks shared with the reporter                             | text               | YES  |     | NULL                |                |
-| private-remarks | Remarks shared with the moderation team                      | text               | YES  |     | NULL                |                |
-| last-editor-uid | Last editor user                                             | mediumint unsigned | YES  |     | NULL                |                |
-| assigned-uid    | Assigned moderator user                                      | mediumint unsigned | YES  |     | NULL                |                |
-| status          | Status of the report, one of Entity\Report::STATUS_*         | tinyint unsigned   | NO   |     | NULL                |                |
-| resolution      | Resolution of the report, one of Entity\Report::RESOLUTION_* | tinyint unsigned   | YES  |     | NULL                |                |
-| created         |                                                              | datetime(6)        | NO   |     | 0001-01-01 00:00:00 |                |
-| edited          | Last time the report has been edited                         | datetime(6)        | YES  |     | NULL                |                |
+| Field           | Description                                                  | Type               | Null | Key | Default                    | Extra          |
+| --------------- | ------------------------------------------------------------ | ------------------ | ---- | --- | -------------------------- | -------------- |
+| id              | sequential ID                                                | int unsigned       | NO   | PRI | NULL                       | auto_increment |
+| uid             | Reporting user                                               | mediumint unsigned | YES  |     | NULL                       |                |
+| reporter-id     | Reporting contact                                            | int unsigned       | YES  |     | NULL                       |                |
+| cid             | Reported contact                                             | int unsigned       | NO   |     | NULL                       |                |
+| gsid            | Reported contact server                                      | int unsigned       | YES  |     | NULL                       |                |
+| comment         | Report                                                       | text               | YES  |     | NULL                       |                |
+| category-id     | Report category, one of Entity\Report::CATEGORY_*            | int unsigned       | NO   |     | 1                          |                |
+| forward         | Forward the report to the remote server                      | boolean            | YES  |     | NULL                       |                |
+| public-remarks  | Remarks shared with the reporter                             | text               | YES  |     | NULL                       |                |
+| private-remarks | Remarks shared with the moderation team                      | text               | YES  |     | NULL                       |                |
+| last-editor-uid | Last editor user                                             | mediumint unsigned | YES  |     | NULL                       |                |
+| assigned-uid    | Assigned moderator user                                      | mediumint unsigned | YES  |     | NULL                       |                |
+| status          | Status of the report, one of Entity\Report::STATUS_*         | tinyint unsigned   | NO   |     | NULL                       |                |
+| resolution      | Resolution of the report, one of Entity\Report::RESOLUTION_* | tinyint unsigned   | YES  |     | NULL                       |                |
+| created         |                                                              | datetime(6)        | NO   |     | 0001-01-01 00:00:00.000000 |                |
+| edited          | Last time the report has been edited                         | datetime(6)        | YES  |     | NULL                       |                |
 
 Indexes
 ------------
index 930e60472f948ebd12d2ac1ed0f8e72c93dc3f47..0c0fd0f80d30839cf94261d08dfee5a0f9a63334 100644 (file)
@@ -42,6 +42,11 @@ class DBA
         */
        const NULL_DATETIME = '0001-01-01 00:00:00';
 
+       /**
+        * Lowest possible datetime(6) value
+        */
+       const NULL_DATETIME6 = '0001-01-01 00:00:00.000000';
+
        public static function connect(): bool
        {
                return DI::dba()->connect();
index 6291d0ffc4b643a2f32bfbad6f2edb2ca10ff92a..6ac52ea9c3074e358b896e4d484d4484d4b53a38 100644 (file)
@@ -284,7 +284,7 @@ class DBStructure
                                        echo $sql;
                                }
                                if ($action) {
-                                       $r = DBA::e($sql);
+                                       $r = DBA::e(str_replace('\\', '\\\\', $sql));
                                        if (!DBA::isResult($r)) {
                                                $errors .= self::printUpdateError($name);
                                        }
@@ -493,7 +493,7 @@ class DBStructure
                                                DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: updating %s table.', DateTimeFormat::utcNow() . ' ' . date('e'), $name));
                                        }
 
-                                       $r = DBA::e($sql3);
+                                       $r = DBA::e(str_replace('\\', '\\\\', $sql3));
                                        if (!DBA::isResult($r)) {
                                                $errors .= self::printUpdateError($sql3);
                                        }
index 318a836efda0e47a908b385eeaa4a9b9d6155eab..cc03bb98e4b396157bdad09e3b0fcbbb6f831211 100644 (file)
@@ -56,7 +56,7 @@ use Friendica\Database\DBA;
 
 // This file is required several times during the test in DbaDefinition which justifies this condition
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1531);
+       define('DB_UPDATE_VERSION', 1532);
 }
 
 return [
@@ -1328,7 +1328,7 @@ return [
                "comment" => "Engagement data per post",
                "fields" => [
                        "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1",  "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
-                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"],
+                       "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "Item owner"],
                        "contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Person, organisation, news, community, relay"],
                        "media-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Type of media in a bit array (1 = image, 2 = video, 4 = audio"],
                        "language" => ["type" => "varbinary(128)", "comment" => "Language information about this post"],
@@ -1736,7 +1736,7 @@ return [
                        "assigned-uid" => ["type" => "mediumint unsigned", "foreign" => ["user" => "uid"], "comment" => "Assigned moderator user"],
                        "status" => ["type" => "tinyint unsigned", "not null" => "1", "comment" => "Status of the report, one of Entity\Report::STATUS_*"],
                        "resolution" => ["type" => "tinyint unsigned", "comment" => "Resolution of the report, one of Entity\Report::RESOLUTION_*"],
-                       "created" => ["type" => "datetime(6)", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
+                       "created" => ["type" => "datetime(6)", "not null" => "1", "default" => DBA::NULL_DATETIME6, "comment" => ""],
                        "edited" => ["type" => "datetime(6)", "comment" => "Last time the report has been edited"],
                ],
                "indexes" => [