@@ -92,10 +92,6 @@ class ArticleAction extends AbstractDatabaseObjectAction
9292 #[\Override]
9393 public function create ()
9494 {
95- if (!empty ($ this ->parameters ['attachmentHandler ' ])) {
96- $ this ->parameters ['data ' ]['attachments ' ] = \count ($ this ->parameters ['attachmentHandler ' ]);
97- }
98-
9995 $ article = parent ::create ();
10096
10197 // save article content
@@ -116,9 +112,17 @@ public function create()
116112 'teaserImageID ' => $ content ['teaserImageID ' ],
117113 'metaTitle ' => $ content ['metaTitle ' ] ?? '' ,
118114 'metaDescription ' => $ content ['metaDescription ' ] ?? '' ,
115+ 'attachments ' => isset ($ content ['attachmentHandler ' ])
116+ ? \count ($ content ['attachmentHandler ' ])
117+ : 0 ,
119118 ]);
120119 $ articleContentEditor = new ArticleContentEditor ($ articleContent );
121120
121+ // update attachments
122+ $ attachmentHandler = $ content ['attachmentHandler ' ] ?? null ;
123+ /** @var ?AttachmentHandler $attachmentHandler */
124+ $ attachmentHandler ?->updateObjectID($ articleContent ->getObjectID ());
125+
122126 // save tags
123127 if (!empty ($ content ['tags ' ])) {
124128 TagEngine::getInstance ()->addObjectTags (
@@ -174,20 +178,12 @@ public function create()
174178 );
175179 }
176180
177- if (!empty ($ this ->parameters ['attachmentHandler ' ])) {
178- $ this ->parameters ['attachmentHandler ' ]->updateObjectID ($ article ->articleID );
179- }
180-
181181 return $ article ;
182182 }
183183
184184 #[\Override]
185185 public function update ()
186186 {
187- if (!empty ($ this ->parameters ['attachmentHandler ' ])) {
188- $ this ->parameters ['data ' ]['attachments ' ] = \count ($ this ->parameters ['attachmentHandler ' ]);
189- }
190-
191187 parent ::update ();
192188
193189 $ isRevert = (!empty ($ this ->parameters ['isRevert ' ]));
@@ -206,17 +202,21 @@ public function update()
206202 $ articleContent = ArticleContent::getArticleContent ($ article ->articleID , ($ languageID ?: null ));
207203 $ articleContentEditor = null ;
208204 if ($ articleContent !== null ) {
209- // update
210- $ articleContentEditor = new ArticleContentEditor ($ articleContent );
211- $ articleContentEditor ->update ([
205+ $ updateData = [
212206 'title ' => $ content ['title ' ],
213207 'teaser ' => $ content ['teaser ' ],
214208 'content ' => $ content ['content ' ],
215209 'imageID ' => ($ isRevert ) ? $ articleContent ->imageID : $ content ['imageID ' ],
216210 'teaserImageID ' => ($ isRevert ) ? $ articleContent ->teaserImageID : $ content ['teaserImageID ' ],
217211 'metaTitle ' => $ content ['metaTitle ' ] ?? '' ,
218212 'metaDescription ' => $ content ['metaDescription ' ] ?? '' ,
219- ]);
213+ ];
214+ if (isset ($ content ['attachmentHandler ' ])) {
215+ $ updateData ['attachments ' ] = \count ($ content ['attachmentHandler ' ]);
216+ }
217+
218+ $ articleContentEditor = new ArticleContentEditor ($ articleContent );
219+ $ articleContentEditor ->update ($ updateData );
220220
221221 $ versionData [] = $ articleContent ;
222222 if ($ articleContent ->content != $ content ['content ' ] || $ articleContent ->teaser != $ content ['teaser ' ] || $ articleContent ->title != $ content ['title ' ]) {
@@ -243,9 +243,18 @@ public function update()
243243 'teaserImageID ' => ($ isRevert ) ? null : $ content ['teaserImageID ' ],
244244 'metaTitle ' => $ content ['metaTitle ' ] ?? '' ,
245245 'metaDescription ' => $ content ['metaDescription ' ] ?? '' ,
246+ 'attachments ' => isset ($ content ['attachmentHandler ' ])
247+ ? \count ($ content ['attachmentHandler ' ])
248+ : 0 ,
246249 ]);
247250 $ articleContentEditor = new ArticleContentEditor ($ articleContent );
248251
252+ // update attachments
253+ if (isset ($ content ['attachmentHandler ' ])) {
254+ /** @var AttachmentHandler $content['attachmentHandler'] */
255+ $ content ['attachmentHandler ' ]->updateObjectID ($ articleContent ->getObjectID ());
256+ }
257+
249258 $ versionData [] = $ articleContent ;
250259 $ hasChanges = true ;
251260 }
@@ -403,11 +412,15 @@ public function delete()
403412 $ this ->readObjects ();
404413 }
405414
406- $ usersToArticles = $ articleIDs = $ articleContentIDs = $ attachmentArticleIDs = [];
415+ $ usersToArticles = $ articleIDs = $ articleContentIDs = $ attachmentArticleContentIDs = [];
407416 foreach ($ this ->getObjects () as $ article ) {
408417 $ articleIDs [] = $ article ->articleID ;
409418 foreach ($ article ->getArticleContents () as $ articleContent ) {
410419 $ articleContentIDs [] = $ articleContent ->articleContentID ;
420+
421+ if ($ articleContent ->attachments ) {
422+ $ attachmentArticleContentIDs [] = $ articleContent ->articleContentID ;
423+ }
411424 }
412425
413426 if ($ article ->publicationStatus == Article::PUBLISHED ) {
@@ -416,10 +429,6 @@ public function delete()
416429 }
417430 $ usersToArticles [$ article ->userID ]--;
418431 }
419-
420- if ($ article ->attachments ) {
421- $ attachmentArticleIDs [] = $ article ->articleID ;
422- }
423432 }
424433
425434 // delete articles
@@ -452,8 +461,11 @@ public function delete()
452461 // update wcf1_user.articles
453462 ArticleEditor::updateArticleCounter ($ usersToArticles );
454463 // delete attachments
455- if (!empty ($ attachmentArticleIDs )) {
456- AttachmentHandler::removeAttachments ('com.woltlab.wcf.article ' , $ attachmentArticleIDs );
464+ if ($ attachmentArticleContentIDs !== []) {
465+ AttachmentHandler::removeAttachments (
466+ 'com.woltlab.wcf.article.content ' ,
467+ $ attachmentArticleContentIDs
468+ );
457469 }
458470 }
459471
0 commit comments