/** * This function can't work properly. * You can't get the cache instance within the cron because no user is connected. * Possible solution: access the cache directly in the filesystem */ private function updateFriends() { $users = \OC::$server->getUserManager()->search(''); $cache = \OCP\ICacheFactory::create('test'); $datadir = \OCP\Config::getSystemValue('datadirectory'); \OCP\Util::writeLog('fbsync', "Cron launched: caching friends...", \OCP\Util::INFO); foreach ($users as $user) { $fbsync = new FacebookController('fbsync', $cache, $datadir . '/' . $user->getUID()); $friends = $fbsync->reload(); if (!$friends) { \OCP\Util::writeLog('fbsync', "Failed to update friends cache for user " . $user->getUID(), \OCP\Util::INFO); } else { \OCP\Util::writeLog('fbsync', count($friends) . " cached for user " . $user->getUID(), \OCP\Util::INFO); } } \OCP\Util::writeLog('fbsync', "Cron finished.", \OCP\Util::INFO); }
/** * Get and set birthday date if not already set */ public function setBirthday() { // We don't want to override data. // We only set birthday to people without one defined if (!isset($this->vcard->FBID)) { return array("error" => 'No FBID', "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100)); } else { if (isset($this->vcard->BDAY)) { return array("error" => 'Already have a birthday', "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100), "birthday" => true); } } // All good, let's do it $birthday = $this->fbController->getBirthday($this->getFBID()); if (!$birthday) { return array("error" => 'No birthday found', "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100)); } else { $birthday = date('Y-m-d', strtotime($birthday)); $this->vcard->add('BDAY', $birthday); $this->save(); return array("error" => false, "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100), "birthday" => $birthday); } }
/** * Match exacts name but use the "People You May Know" list * @NoAdminRequired */ public function suggestMatch() { $contacts = $this->getList(); $contactsName = array(); $edited = 0; // List contacts by Name // Use strtolower to avoid errors based on typo foreach ($contacts as $contact) { $contactsName[strtolower($contact->getName())] = $contact; } $friends = $this->fbController->getsuggestedFriends(); // Parse all friends foreach ($friends as $fbid => $friend) { $friend = strtolower($friend); // Match exact name if (isset($contactsName[$friend])) { if ($contactsName[$friend]->getFBID() != $fbid) { $edited++; $contactsName[$friend]->setFBID($fbid); } } } return $edited; }