]> git.mxchange.org Git - friendica.git/commitdiff
Get rid of the table "unique_contacts"
authorMichael Vogel <icarus@dabo.de>
Wed, 6 Jan 2016 21:23:12 +0000 (22:23 +0100)
committerMichael Vogel <icarus@dabo.de>
Wed, 6 Jan 2016 21:23:12 +0000 (22:23 +0100)
database.sql
doc/database.md
doc/database/db_unique_contacts.md [deleted file]
friendica_test_data.sql
include/Contact.php
include/api.php
include/dbstructure.php
include/ostatus.php
mod/admin.php
mod/display.php

index 90604457bc8e16972079624fc39378e46891ac8e..4e6f3d35c7f62ff260cba155e3be2b68882e6e84 100644 (file)
@@ -332,6 +332,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
        `about` text NOT NULL,
        `keywords` text NOT NULL,
        `gender` varchar(32) NOT NULL DEFAULT '',
+       `birthday` varchar(32) NOT NULL DEFAULT '0000-00-00',
        `community` tinyint(1) NOT NULL DEFAULT 0,
        `hide` tinyint(1) NOT NULL DEFAULT 0,
        `nsfw` tinyint(1) NOT NULL DEFAULT 0,
@@ -1003,21 +1004,6 @@ CREATE TABLE IF NOT EXISTS `tokens` (
         PRIMARY KEY(`id`)
 ) DEFAULT CHARSET=utf8;
 
---
--- TABLE unique_contacts
---
-CREATE TABLE IF NOT EXISTS `unique_contacts` (
-       `id` int(11) NOT NULL auto_increment,
-       `url` varchar(255) NOT NULL DEFAULT '',
-       `nick` varchar(255) NOT NULL DEFAULT '',
-       `name` varchar(255) NOT NULL DEFAULT '',
-       `avatar` varchar(255) NOT NULL DEFAULT '',
-       `location` varchar(255) NOT NULL DEFAULT '',
-       `about` text NOT NULL,
-        PRIMARY KEY(`id`),
-        INDEX `url` (`url`)
-) DEFAULT CHARSET=utf8;
-
 --
 -- TABLE user
 --
index 1893f77d0cb3362a763d96b0a3673c83b77a55e1..2ef77c6dad7e2a0a9b4608b5bbaf89a219b5b446 100644 (file)
@@ -54,7 +54,6 @@ Database Tables
 | [term](help/database/db_term)                        | item taxonomy (categories, tags, etc.) table     |
 | [thread](help/database/db_thread)                    |                                                  |
 | [tokens](help/database/db_tokens)                    | OAuth usage                                      |
-| [unique_contacts](help/database/db_unique_contacts)  |                                                  |
 | [user](help/database/db_user)                        | local user table                                 |
 | [userd](help/database/db_userd)                      |                                                  |
 | [workerqueue](help/database/db_workerqueue)          |                                                  |
diff --git a/doc/database/db_unique_contacts.md b/doc/database/db_unique_contacts.md
deleted file mode 100644 (file)
index 491da6a..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-Table unique_contacts
-=====================
-
-| Field    | Description      | Type         | Null | Key | Default | Extra          |
-|----------|------------------|--------------|------|-----|---------|----------------|
-| id       | sequential ID    | int(11)      | NO   | PRI | NULL    | auto_increment |
-| url      |                  | varchar(255) | NO   | MUL |         |                |
-| nick     |                  | varchar(255) | NO   |     |         |                |
-| name     |                  | varchar(255) | NO   |     |         |                |
-| avatar   |                  | varchar(255) | NO   |     |         |                |
-| location |                  | varchar(255) | NO   |     |         |                |
-| about    |                  | text         | NO   |     | NULL    |                |
-
-Return to [database documentation](help/database)
index c39a0576514c2524ce778d6dd79ebac855a1693e..45080e44d0fd9a3f92e4d53417184634a7a1a957 100644 (file)
@@ -1657,35 +1657,6 @@ LOCK TABLES `tokens` WRITE;
 /*!40000 ALTER TABLE `tokens` ENABLE KEYS */;
 UNLOCK TABLES;
 
---
--- Table structure for table `unique_contacts`
---
-
-DROP TABLE IF EXISTS `unique_contacts`;
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `unique_contacts` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `url` varchar(255) NOT NULL DEFAULT '',
-  `nick` varchar(255) NOT NULL DEFAULT '',
-  `name` varchar(255) NOT NULL DEFAULT '',
-  `avatar` varchar(255) NOT NULL DEFAULT '',
-  `location` varchar(255) NOT NULL DEFAULT '',
-  `about` text NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `url` (`url`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping data for table `unique_contacts`
---
-
-LOCK TABLES `unique_contacts` WRITE;
-/*!40000 ALTER TABLE `unique_contacts` DISABLE KEYS */;
-/*!40000 ALTER TABLE `unique_contacts` ENABLE KEYS */;
-UNLOCK TABLES;
-
 --
 -- Table structure for table `user`
 --
index a3cbbfed15265c765a8bd6278e1f6c160e4f76fe..3185e8734829d39b14d6c1492fde63916a90d9ee 100644 (file)
@@ -205,19 +205,6 @@ function get_contact_details_by_url($url, $uid = -1) {
                if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND
                        in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
                        proc_run('php',"include/update_gcontact.php", $profile["gid"]);
-
-       } else {
-               $r = q("SELECT `url`, `name`, `nick`, `avatar` AS `photo`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'",
-                       dbesc(normalise_link($url)));
-
-               if (count($r)) {
-                       $profile = $r[0];
-                       $profile["keywords"] = "";
-                       $profile["gender"] = "";
-                       $profile["community"] = false;
-                       $profile["network"] = "";
-                       $profile["addr"] = "";
-               }
        }
 
        // Fetching further contact data from the contact table
index 790894d3fba2c0365c57557960ca581cf9e31a46..3bc7c8bab90db41ff9e4401c8763747abd0a112b 100644 (file)
         *              Contact url or False if contact id is unknown
         */
        function api_unique_id_to_url($id){
-               $r = q("SELECT `url` FROM `unique_contacts` WHERE `id`=%d LIMIT 1",
+               $r = q("SELECT `url` FROM `gcontact` WHERE `id`=%d LIMIT 1",
                        intval($id));
                if ($r)
                        return ($r[0]["url"]);
                        $r = array();
 
                        if ($url != "")
-                               $r = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $url);
-                       elseif ($nick != "")
-                               $r = q("SELECT * FROM `unique_contacts` WHERE `nick`='%s' LIMIT 1", $nick);
+                               $r = q("SELECT * FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($url)));
 
                        if ($r) {
                                // If no nick where given, extract it from the address
                                        'id_str' => (string) $r[0]["id"],
                                        'name' => $r[0]["name"],
                                        'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
-                                       'location' => NULL,
-                                       'description' => NULL,
+                                       'location' => $r[0]["location"],
+                                       'description' => $r[0]["about"],
                                        'url' => $r[0]["url"],
                                        'protected' => false,
                                        'followers_count' => 0,
                                        'friends_count' => 0,
                                        'listed_count' => 0,
-                                       'created_at' => api_date(0),
+                                       'created_at' => api_date($r[0]["created"]),
                                        'favourites_count' => 0,
                                        'utc_offset' => 0,
                                        'time_zone' => 'UTC',
                                        'contributors_enabled' => false,
                                        'is_translator' => false,
                                        'is_translation_enabled' => false,
-                                       'profile_image_url' => $r[0]["avatar"],
-                                       'profile_image_url_https' => $r[0]["avatar"],
+                                       'profile_image_url' => $r[0]["photo"],
+                                       'profile_image_url_https' => $r[0]["photo"],
                                        'following' => false,
                                        'follow_request_sent' => false,
                                        'notifications' => false,
                                        'uid' => 0,
                                        'cid' => 0,
                                        'self' => 0,
-                                       'network' => '',
+                                       'network' => $r[0]["network"],
                                );
 
                                return $ret;
                        $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
                }
 
-               // Fetching unique id
-               $r = q("SELECT id FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
-
-               // If not there, then add it
-               if (count($r) == 0) {
-                       q("INSERT INTO `unique_contacts` (`url`, `name`, `nick`, `avatar`) VALUES ('%s', '%s', '%s', '%s')",
-                               dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
-
-                       $r = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
-               }
-
                $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
 
+               $gcontact_id  = get_gcontact_id(array("url" => $uinfo[0]['url'], "network" => $uinfo[0]['network'],
+                                                       "photo" => $uinfo[0]['micro'], "name" => $uinfo[0]['name']));
+
                $ret = Array(
-                       'id' => intval($r[0]['id']),
-                       'id_str' => (string) intval($r[0]['id']),
+                       'id' => intval($gcontact_id),
+                       'id_str' => (string) intval($gcontact_id),
                        'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
                        'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
                        'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
 
        function api_item_get_user(&$a, $item) {
 
-               $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
-                       dbesc(normalise_link($item['author-link'])));
-
-               if (count($author) == 0) {
-                       q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
-                               dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"]));
-
-                       $author = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
-                               dbesc(normalise_link($item['author-link'])));
-               } else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) {
-                       $r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
-                               dbesc($item["author-name"]), dbesc($item["author-avatar"]),
-                               dbesc(normalise_link($item["author-link"])));
+               // Make sure that there is an entry in the global contacts for author and owner
+               get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
+                                       "photo" => $item['author-avatar'], "name" => $item['author-name']));
 
-                       if (!$r)
-                               q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
-                                       dbesc($item["author-name"]), dbesc($item["author-avatar"]),
-                                       dbesc(normalise_link($item["author-link"])));
-               }
-
-               $owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
-                       dbesc(normalise_link($item['owner-link'])));
-
-               if (count($owner) == 0) {
-                       q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
-                               dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"]));
-
-                       $owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
-                               dbesc(normalise_link($item['owner-link'])));
-               } else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) {
-                       $r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
-                               dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
-                               dbesc(normalise_link($item["owner-link"])));
-
-                       if (!$r)
-                               q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
-                                       dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
-                                       dbesc(normalise_link($item["owner-link"])));
-               }
+               get_gcontact_id(array("url" => $item['owner-link'], "network" => $item['network'],
+                                       "photo" => $item['owner-avatar'], "name" => $item['owner-name']));
 
                // Comments in threads may appear as wall-to-wall postings.
                // So only take the owner at the top posting.
                                $in_reply_to_status_id= intval($lastwall['parent']);
                                $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
 
-                               $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
+                               $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
                                if ($r) {
                                        if ($r[0]['nick'] == "")
                                                $r[0]['nick'] = api_get_nick($r[0]["url"]);
                                        $in_reply_to_status_id = intval($lastwall['parent']);
                                        $in_reply_to_status_id_str = (string) intval($lastwall['parent']);
 
-                                       $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
+                                       $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
                                        if ($r) {
                                                if ($r[0]['nick'] == "")
                                                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                $userlist = array();
 
                if (isset($_GET["q"])) {
-                       $r = q("SELECT id FROM `unique_contacts` WHERE `name`='%s'", dbesc($_GET["q"]));
+                       $r = q("SELECT id FROM `gcontact` WHERE `name`='%s'", dbesc($_GET["q"]));
                        if (!count($r))
-                               $r = q("SELECT `id` FROM `unique_contacts` WHERE `nick`='%s'", dbesc($_GET["q"]));
+                               $r = q("SELECT `id` FROM `gcontact` WHERE `nick`='%s'", dbesc($_GET["q"]));
 
                        if (count($r)) {
                                foreach ($r AS $user) {
                                        intval(api_user()),
                                        intval($in_reply_to_status_id));
                                if ($r) {
-                                       $r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
+                                       $r = q("SELECT * FROM `gcontact` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
 
                                        if ($r) {
                                                if ($r[0]['nick'] == "")
 
                $stringify_ids = (x($_REQUEST,'stringify_ids')?$_REQUEST['stringify_ids']:false);
 
-               $r = q("SELECT `unique_contacts`.`id` FROM `contact`, `unique_contacts` WHERE `contact`.`nurl` = `unique_contacts`.`url` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
+               $r = q("SELECT `gcontact`.`id` FROM `contact`, `gcontact` WHERE `contact`.`nurl` = `gcontact`.`nurl` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
                        intval(api_user())
                );
 
 
                //}
 
-               if ($nick != "") {
-                       q("UPDATE `unique_contacts` SET `nick` = '%s' WHERE `nick` != '%s' AND url = '%s'",
-                               dbesc($nick), dbesc($nick), dbesc(normalise_link($profile)));
+               if ($nick != "")
                        return($nick);
-               }
 
                return(false);
        }
index 1fc388d6c1afa4b98b4c9b458851059430987b6b..1b414c70fbc02f8dab4c8306f2b02cac434ea699 100644 (file)
@@ -1340,21 +1340,6 @@ function db_definition() {
                                        "PRIMARY" => array("id"),
                                        )
                        );
-       $database["unique_contacts"] = array(
-                       "fields" => array(
-                                       "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
-                                       "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
-                                       "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
-                                       "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
-                                       "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
-                                       "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
-                                       "about" => array("type" => "text", "not null" => "1"),
-                                       ),
-                       "indexes" => array(
-                                       "PRIMARY" => array("id"),
-                                       "url" => array("url"),
-                                       )
-                       );
        $database["user"] = array(
                        "fields" => array(
                                        "uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
index 4a999ae2c58c6792390f583f75e967a9ffa91fd2..c1b8233298827ccde26d96c7d20e376bf64185a1 100644 (file)
@@ -1452,9 +1452,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false)
                $repeated_owner["about"] = "";
                $repeated_owner["uid"] = 0;
 
-               $r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"]));
+               // Fetch the missing data from the global contacts
+               $r =q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($repeated_item["author-link"]));
                if ($r) {
-                       $repeated_owner["nick"] = $r[0]["nick"];
+                       if ($r[0]["nick"] != "")
+                               $repeated_owner["nick"] = $r[0]["nick"];
+
                        $repeated_owner["location"] = $r[0]["location"];
                        $repeated_owner["about"] = $r[0]["about"];
                }
index 9e330fd1dc0380bf127d61be8016a67cbb10c8f4..0636a342018a69ffe046a62c57cef068a89db4db 100644 (file)
@@ -341,7 +341,7 @@ function admin_page_site_post(&$a){
                update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
                update_table("term", array('url'), $old_url, $new_url);
                update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url);
-               update_table("unique_contacts", array('url'), $old_url, $new_url);
+               update_table("gcontact", array('photo','url','nurl','server_url'), $old_url, $new_url);
                update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
 
                // update config
index 6d1f417e710ad8b861ebd9f99dda8f9633b4d92c..c173c5a9124152f430c78462599604e3cf878bf3 100644 (file)
@@ -179,8 +179,8 @@ function display_fetchauthor($a, $item) {
                        $profiledata["nickname"] = $r[0]["nick"];
        }
 
-       // Fetching profile data from unique contacts
-       $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
+       // Fetching profile data from global contacts
+       $r = q("SELECT `photo`, `nick`, `addr`, `location`, `about`, `gender` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
        if (count($r)) {
                if ($profiledata["photo"] == "")
                        $profiledata["photo"] = $r[0]["avatar"];
@@ -190,6 +190,10 @@ function display_fetchauthor($a, $item) {
                        $profiledata["about"] = $r[0]["about"];
                if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
                        $profiledata["nickname"] = $r[0]["nick"];
+               if ($profiledata["gender"] == "")
+                       $profiledata["gender"] = $r[0]["gender"];
+               if ($profiledata["addr"] == "")
+                       $profiledata["addr"] = $r[0]["addr"];
        }
 
        if (local_user()) {