]> git.mxchange.org Git - friendica.git/blobdiff - include/dbstructure.php
Issue 3857: There is the possibility of a bad handling of dislikes
[friendica.git] / include / dbstructure.php
index b8cf8e57ac4881f846cc03a4ec9f94c5c5cc1edf..0b15805b4df8fd3ee26878a925810625a02ee43b 100644 (file)
@@ -130,10 +130,8 @@ function table_structure($table) {
                        }
 
                        $column = $index["Column_name"];
-                       // On utf8mb4 a varchar index can only have a length of 191
-                       // The "show index" command sometimes returns this value although this value wasn't added manually.
-                       // Because we don't want to add this number to every index, we ignore bigger numbers
-                       if (($index["Sub_part"] != "") && (($index["Sub_part"] < 191) || ($index["Key_name"] == "PRIMARY"))) {
+
+                       if (($index["Sub_part"] != "")) {
                                $column .= "(".$index["Sub_part"].")";
                        }
 
@@ -412,17 +410,18 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
 
                        if ($verbose) {
                                // Ensure index conversion to unique removes duplicates
-                               if ($is_unique) {
+                               if ($is_unique && ($temp_name != $name)) {
                                        if ($ignore != "") {
                                                echo "SET session old_alter_table=1;\n";
                                        } else {
+                                               echo "DROP TABLE IF EXISTS `".$temp_name."`;\n";
                                                echo "CREATE TABLE `".$temp_name."` LIKE `".$name."`;\n";
                                        }
                                }
 
                                echo $sql3."\n";
 
-                               if ($is_unique) {
+                               if ($is_unique && ($temp_name != $name)) {
                                        if ($ignore != "") {
                                                echo "SET session old_alter_table=0;\n";
                                        } else {
@@ -437,10 +436,16 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                Config::set('system', 'maintenance_reason', sprintf(t('%s: updating %s table.'), dbm::date().' '.date('e'), $name));
 
                                // Ensure index conversion to unique removes duplicates
-                               if ($is_unique) {
+                               if ($is_unique && ($temp_name != $name)) {
                                        if ($ignore != "") {
                                                dba::e("SET session old_alter_table=1;");
                                        } else {
+                                               dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
+                                               if (!dbm::is_result($r)) {
+                                                       $errors .= print_update_error($sql3);
+                                                       return $errors;
+                                               }
+
                                                $r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
                                                if (!dbm::is_result($r)) {
                                                        $errors .= print_update_error($sql3);
@@ -453,7 +458,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
                                if (!dbm::is_result($r)) {
                                        $errors .= print_update_error($sql3);
                                }
-                               if ($is_unique) {
+                               if ($is_unique && ($temp_name != $name)) {
                                        if ($ignore != "") {
                                                dba::e("SET session old_alter_table=0;");
                                        } else {
@@ -810,8 +815,8 @@ function db_definition() {
                                        "addr_uid" => array("addr(32)", "uid"),
                                        "nurl_uid" => array("nurl(32)", "uid"),
                                        "nick_uid" => array("nick(32)", "uid"),
-                                       "dfrn-id" => array("dfrn-id"),
-                                       "issued-id" => array("issued-id"),
+                                       "dfrn-id" => array("dfrn-id(64)"),
+                                       "issued-id" => array("issued-id(64)"),
                                        )
                        );
        $database["conv"] = array(
@@ -1155,11 +1160,11 @@ function db_definition() {
                                        ),
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
-                                       "guid" => array("guid"),
-                                       "uri" => array("uri"),
+                                       "guid" => array("guid(191)"),
+                                       "uri" => array("uri(191)"),
                                        "parent" => array("parent"),
-                                       "parent-uri" => array("parent-uri"),
-                                       "extid" => array("extid"),
+                                       "parent-uri" => array("parent-uri(191)"),
+                                       "extid" => array("extid(191)"),
                                        "uid_id" => array("uid","id"),
                                        "uid_contactid_id" => array("uid","contact-id","id"),
                                        "uid_created" => array("uid","created"),
@@ -1172,7 +1177,7 @@ function db_definition() {
                                        "authorid_created" => array("author-id","created"),
                                        "ownerid" => array("owner-id"),
                                        "uid_uri" => array("uid", "uri(190)"),
-                                       "resource-id" => array("resource-id"),
+                                       "resource-id" => array("resource-id(191)"),
                                        "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
                                        "uid_type_changed" => array("uid","type(190)","changed"),
                                        "contactid_verb" => array("contact-id","verb(190)"),
@@ -1194,7 +1199,7 @@ function db_definition() {
                        "indexes" => array(
                                        "PRIMARY" => array("id"),
                                        "uid" => array("uid"),
-                                       "sid" => array("sid"),
+                                       "sid" => array("sid(32)"),
                                        "service" => array("service(32)"),
                                        "iid" => array("iid"),
                                        )
@@ -1236,7 +1241,7 @@ function db_definition() {
                                        "convid" => array("convid"),
                                        "uri" => array("uri(64)"),
                                        "parent-uri" => array("parent-uri(64)"),
-                                       "contactid" => array("contact-id"),
+                                       "contactid" => array("contact-id(32)"),
                                        )
                        );
        $database["mailacct"] = array(
@@ -1587,7 +1592,7 @@ function db_definition() {
                                        "uid" => array("uid"),
                                        "spam" => array("spam"),
                                        "ham" => array("ham"),
-                                       "term" => array("term"),
+                                       "term" => array("term(32)"),
                                        )
                        );
        $database["term"] = array(
@@ -1708,7 +1713,6 @@ function db_definition() {
                                        "account_expired" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
                                        "account_expires_on" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
                                        "expire_notification_sent" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
-                                       "service_class" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
                                        "def_gid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
                                        "allow_cid" => array("type" => "mediumtext"),
                                        "allow_gid" => array("type" => "mediumtext"),