@@ -1223,16 +1223,13 @@ public function save($userID=false) {
12231223 if (!empty ($ this ->changed ['creators ' ])) {
12241224 $ indexes = array_keys ($ this ->changed ['creators ' ]);
12251225
1226- // TODO: group queries
1227-
12281226 $ creatorsArray = [];
12291227 foreach ($ indexes as $ orderIndex ) {
12301228 $ creator = $ this ->getCreator ($ orderIndex );
1231- $ creator ->itemID = $ itemID ;
12321229 $ creatorsArray [] = $ creator ;
12331230 }
12341231
1235- Zotero_Creators::bulkInsert ($ this ->libraryID , $ creatorsArray );
1232+ Zotero_Creators::bulkInsert ($ this ->libraryID , $ itemID , $ creatorsArray );
12361233
12371234 }
12381235
@@ -1527,10 +1524,7 @@ public function save($userID=false) {
15271524 if ($ this ->isEmbeddedImageAttachment ()) {
15281525 throw new Exception ("Embedded image attachments cannot have tags " );
15291526 }
1530- foreach ($ this ->tags as $ tag ) {
1531- $ tag ->itemID = $ itemID ;
1532- }
1533- Zotero_Tags::bulkInsert ($ this ->libraryID , $ this ->tags );
1527+ Zotero_Tags::bulkInsert ($ this ->libraryID , $ itemID , $ this ->tags );
15341528 }
15351529
15361530 // Related items
@@ -1708,26 +1702,14 @@ public function save($userID=false) {
17081702 //
17091703 if (!empty ($ this ->changed ['creators ' ])) {
17101704 $ indexes = array_keys ($ this ->changed ['creators ' ]);
1711-
1705+
1706+ $ toAdd = [];
17121707 foreach ($ indexes as $ orderIndex ) {
1713- Z_Core::debug ('Creator in position ' . $ orderIndex . ' has changed ' , 4 );
17141708 $ creator = $ this ->getCreator ($ orderIndex );
1715-
1716- // TODO: can do one update instead of delete and save()
1717- $ sql2 = 'DELETE FROM itemCreators WHERE itemID=? AND orderIndex=? ' ;
1718- Zotero_DB::query ($ sql2 , array ($ this ->_id , $ orderIndex ), $ shardID );
1719-
1720- if (!$ creator ) {
1721- continue ;
1722- }
1723-
1724- if ($ creator ->hasChanged () || !isset ($ creator ->id )) {
1725- $ creator ->itemID = $ this ->_id ;
1726- Z_Core::debug ("Auto-saving changed creator {$ creator ->id }" );
1727- $ creator ->save ();
1728- }
1729-
1709+ $ toAdd [] = $ creator ;
17301710 }
1711+ Zotero_Creators::bulkDelete ($ this ->libraryID , $ this ->_id , $ indexes );
1712+ Zotero_Creators::bulkInsert ($ this ->libraryID , $ this ->_id , $ toAdd );
17311713
17321714 }
17331715
@@ -2162,10 +2144,7 @@ public function save($userID=false) {
21622144 $ toAdd = array_udiff ($ newTags , $ oldTags , $ cmp );
21632145 $ toRemove = array_udiff ($ oldTags , $ newTags , $ cmp );
21642146
2165- foreach ($ toAdd as $ tag ) {
2166- $ tag ->itemID = $ this ->_id ;
2167- }
2168- Zotero_Tags::bulkInsert ($ this ->_libraryID , $ toAdd );
2147+ Zotero_Tags::bulkInsert ($ this ->_libraryID , $ this ->_id , $ toAdd );
21692148 Zotero_Tags::bulkDelete ($ this ->_libraryID , $ this ->_id , $ toRemove );
21702149 }
21712150
@@ -3676,7 +3655,7 @@ public function setTags($newTags) {
36763655 continue ;
36773656 }
36783657 $ version = Zotero_Libraries::getUpdatedVersion ($ this ->libraryID );
3679- $ this ->tags [] = new Zotero_Tag (null , $ this ->libraryID , null , $ name , $ type , $ version );
3658+ $ this ->tags [] = new Zotero_Tag (null , $ this ->libraryID , $ name , $ type , $ version );
36803659 $ this ->changed ['tags ' ] = true ;
36813660 }
36823661 $ toRemove = array_diff ($ existingTagNames , $ foundNames );
@@ -4685,7 +4664,7 @@ protected function loadCreators($reload = false) {
46854664 }
46864665
46874666 foreach ($ creators as $ creator ) {
4688- $ creatorObj = new Zotero_Creator ($ creator ['creatorID ' ], $ this ->_libraryID , null , $ creator ['firstName ' ], $ creator ['lastName ' ], $ creator ['fieldMode ' ], $ creator ['creatorTypeID ' ], $ creator ['orderIndex ' ]);
4667+ $ creatorObj = new Zotero_Creator ($ creator ['creatorID ' ], $ this ->_libraryID , $ creator ['firstName ' ], $ creator ['lastName ' ], $ creator ['fieldMode ' ], $ creator ['creatorTypeID ' ], $ creator ['orderIndex ' ]);
46894668
46904669 $ this ->creators [$ creator ['orderIndex ' ]] = $ creatorObj ;
46914670 }
@@ -4731,7 +4710,7 @@ protected function loadTags($reload = false) {
47314710 $ this ->tags = [];
47324711 if ($ tags ) {
47334712 foreach ($ tags as $ tag ) {
4734- $ this ->tags [] = new Zotero_Tag ($ tag ['tagID ' ], $ this ->libraryID , $ tag ['itemID ' ], $ tag [ ' name ' ], $ tag ['type ' ], $ tag ['version ' ]);
4713+ $ this ->tags [] = new Zotero_Tag ($ tag ['tagID ' ], $ this ->libraryID , $ tag ['name ' ], $ tag ['type ' ], $ tag ['version ' ]);
47354714 }
47364715 }
47374716 $ this ->loaded ['tags ' ] = true ;
0 commit comments