/** * @return {array<string>} An array of related item keys */ private function getRelatedItems() { $predicate = Zotero_Relations::$relatedItemPredicate; $relations = $this->getRelations(); if (empty($relations->$predicate)) { return []; } $relatedItemURIs = is_string($relations->$predicate) ? [$relations->$predicate] : $relations->$predicate; // Pull out object values from related-item relations, turn into items, and pull out keys $keys = []; foreach ($relatedItemURIs as $relatedItemURI) { $item = Zotero_URI::getURIItem($relatedItemURI); if ($item) { $keys[] = $item->key; } } return array_unique($keys); }
public static function purge($libraryID) { $sql = "SELECT subject FROM relations " . "WHERE libraryID=? AND predicate!=? " . "UNION " . "SELECT object FROM relations " . "WHERE libraryID=? AND predicate!=?"; $uris = Zotero . DB . columnQuery($sql, array($libraryID, self::$deletedItemPredicate, $libraryID, self::$deletedItemPredicate), Zotero_Shards::getByLibraryID($libraryID)); if ($uris) { $prefix = Zotero_URI::getBaseURI(); Zotero_DB::beginTransaction(); foreach ($uris as $uri) { // Skip URIs that don't begin with the default prefix, // since they don't correspond to local items if (strpos($uri, $prefix) === false) { continue; } if (preg_match('/\\/items\\//', $uri) && !Zotero_URI::getURIItem($uri)) { self::eraseByURI($uri); } if (preg_match('/\\/collections\\//', $uri) && !Zotero_URI::getURICollection($uri)) { self::eraseByURI($uri); } } Zotero_DB::commit(); } }