forked from piernov/zotprime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotations and embedded-image attachments [DB update]
1) Apply triggers.sql to all DB shards. 2) Run 'annotations' to make additional DB schema changes. 3) Push the new code with $ITL=false in Zotero_Items::search() to start populating the new itemTopLevel table on change without using it for search. 4) Run 'itemTopLevelPopulate' to populate itemTopLevel for existing items. It can be safely re-run. 5) Enable $ITL in Zotero_Items::search() to start using itemTopLevel for searches.
- Loading branch information
Showing
26 changed files
with
2,110 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/php -d mysqlnd.net_read_timeout=3600 | ||
<?php | ||
set_include_path("../../../include"); | ||
require("header.inc.php"); | ||
|
||
$startShard = !empty($argv[1]) ? $argv[1] : 1; | ||
|
||
$shardIDs = Zotero_DB::columnQuery("SELECT shardID FROM shards WHERE shardID >= ? ORDER BY shardID", $startShard); | ||
foreach ($shardIDs as $shardID) { | ||
echo "Shard: $shardID\n"; | ||
|
||
Zotero_Admin_DB::query("ALTER TABLE `itemAttachments` CHANGE `linkMode` `linkMode` ENUM( 'IMPORTED_FILE', 'IMPORTED_URL', 'LINKED_FILE', 'LINKED_URL', 'EMBEDDED_IMAGE' )", false, $shardID); | ||
Zotero_Admin_DB::query("CREATE TABLE `itemAnnotations` ( `itemID` int(10) unsigned NOT NULL, `parentItemID` int(10) unsigned NOT NULL, `type` enum('highlight','note','image') CHARACTER SET ascii COLLATE ascii_bin NOT NULL, `text` varchar(10000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL, `comment` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL, `color` char(6) CHARACTER SET ascii NOT NULL, `pageLabel` varchar(50) NOT NULL, `sortIndex` varchar(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, `position` varchar(20000) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (`itemID`), KEY `parentItemID` (`parentItemID`), CONSTRAINT `itemAnnotations_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE, CONSTRAINT `itemAnnotations_ibfk_2` FOREIGN KEY (`parentItemID`) REFERENCES `itemAttachments` (`itemID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", false, $shardID); | ||
Zotero_Admin_DB::query("CREATE TABLE `itemTopLevel` ( `itemID` int(10) unsigned NOT NULL, `topLevelItemID` int(10) unsigned NOT NULL, PRIMARY KEY (`itemID`), KEY `itemTopLevel_ibfk_2` (`topLevelItemID`), CONSTRAINT `itemTopLevel_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE, CONSTRAINT `itemTopLevel_ibfk_2` FOREIGN KEY (`topLevelItemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", false, $shardID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/php -d mysqlnd.net_read_timeout=3600 | ||
<?php | ||
set_include_path("../../../include"); | ||
require("header.inc.php"); | ||
|
||
$startShard = !empty($argv[1]) ? $argv[1] : 1; | ||
|
||
$shardIDs = Zotero_DB::columnQuery("SELECT shardID FROM shards WHERE shardID >= ? ORDER BY shardID", $startShard); | ||
foreach ($shardIDs as $shardID) { | ||
echo "Shard: $shardID\n"; | ||
|
||
Zotero_DB::query("INSERT IGNORE INTO itemTopLevel SELECT itemID, sourceItemID FROM itemAttachments WHERE sourceItemID IS NOT NULL UNION SELECT itemID, sourceItemID FROM itemNotes WHERE sourceItemID IS NOT NULL", false, $shardID); | ||
Zotero_DB::query("DELETE ITL FROM itemTopLevel ITL LEFT JOIN (SELECT itemID, sourceItemID FROM itemAttachments UNION SELECT itemID, sourceItemID FROM itemNotes) S ON (ITL.itemID=S.itemID AND ITL.topLevelItemID=S.sourceItemID) WHERE S.itemID IS NULL", false, $shardID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
delimiter // | ||
|
||
DROP TRIGGER IF EXISTS fki_itemAttachments;// | ||
CREATE TRIGGER fki_itemAttachments | ||
BEFORE INSERT ON itemAttachments | ||
FOR EACH ROW BEGIN | ||
-- itemAttachments libraryID | ||
IF NEW.sourceItemID IS NOT NULL AND (SELECT libraryID FROM items WHERE itemID = NEW.itemID) != (SELECT libraryID FROM items WHERE itemID = NEW.sourceItemID) THEN | ||
SELECT libraryIDs_do_not_match INTO @failure FROM itemAttachments; | ||
END IF; | ||
|
||
-- Make sure this is an attachment item | ||
IF ((SELECT itemTypeID FROM items WHERE itemID = NEW.itemID) != 14) THEN | ||
SELECT not_an_attachment INTO @failure FROM items; | ||
END IF; | ||
|
||
-- If there's a parent, reject if it's an attachment or it's a note and this isn't an embedded-image attachment | ||
SET @parentItemTypeID = IF(NEW.sourceItemID IS NULL, NULL, (SELECT itemTypeID FROM items WHERE itemID = NEW.sourceItemID)); | ||
IF (@parentItemTypeID = 14 OR (@parentItemTypeID = 1 AND NEW.linkMode != 'EMBEDDED_IMAGE')) THEN | ||
SELECT invalid_parent INTO @failure FROM items; | ||
END IF; | ||
|
||
-- If child, make sure attachment is not in a collection | ||
IF (NEW.sourceItemID IS NOT NULL AND (SELECT COUNT(*) FROM collectionItems WHERE itemID=NEW.itemID)>0) THEN | ||
SELECT collection_item_must_be_top_level INTO @failure FROM collectionItems; | ||
END IF; | ||
END;// | ||
|
||
DROP TRIGGER IF EXISTS fku_itemAttachments_libraryID;// | ||
CREATE TRIGGER fku_itemAttachments_libraryID | ||
BEFORE UPDATE ON itemAttachments | ||
FOR EACH ROW BEGIN | ||
IF NEW.sourceItemID IS NOT NULL AND (SELECT libraryID FROM items WHERE itemID = NEW.itemID) != (SELECT libraryID FROM items WHERE itemID = NEW.sourceItemID) THEN | ||
SELECT libraryIDs_do_not_match INTO @failure FROM itemAttachments; | ||
END IF; | ||
|
||
-- If there's a parent, reject if it's an attachment or it's a note and this isn't an embedded-image attachment | ||
SET @parentItemTypeID = IF(NEW.sourceItemID IS NULL, NULL, (SELECT itemTypeID FROM items WHERE itemID = NEW.sourceItemID)); | ||
IF (@parentItemTypeID = 14 OR (@parentItemTypeID = 1 AND NEW.linkMode != 'EMBEDDED_IMAGE')) THEN | ||
SELECT invalid_parent INTO @failure FROM items; | ||
END IF; | ||
|
||
-- If child, make sure attachment is not in a collection | ||
IF (NEW.sourceItemID IS NOT NULL AND (SELECT COUNT(*) FROM collectionItems WHERE itemID=NEW.itemID)>0) THEN | ||
SELECT collection_item_must_be_top_level INTO @failure FROM collectionItems; | ||
END IF; | ||
END;// | ||
|
||
delimiter ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.