Add recent activity events for articles
authorJoshua Rüsweg <josh@bastelstu.be>
Thu, 30 Aug 2018 15:26:39 +0000 (17:26 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Thu, 30 Aug 2018 15:26:39 +0000 (17:26 +0200)
See #2625

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/data/article/ArticleAction.class.php
wcfsetup/install/files/lib/system/user/activity/event/ArticleUserActivityEvent.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 20dc196cac0f3d3b171ba2b47655c67d7070b7b0..5599d13ddb6e68cdc3ab4b78148974bba93e2e90 100644 (file)
                        <classname>wcf\system\user\notification\object\type\ArticleUserNotificationObjectType</classname>
                        <category>com.woltlab.wcf.page</category>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.article.recentActivityEvent</name>
+                       <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
+                       <classname>wcf\system\user\activity\event\ArticleUserActivityEvent</classname>
+               </type>
                <!-- /articles -->
                
                <type>
index ee7eb976f8035060037d6be02571b28534587591..737c7b575763c20371de6af72efdbf7a211b17e1 100644 (file)
@@ -16,6 +16,7 @@ use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\request\LinkHandler;
 use wcf\system\search\SearchIndexManager;
 use wcf\system\tagging\TagEngine;
+use wcf\system\user\activity\event\UserActivityEventHandler;
 use wcf\system\user\notification\object\ArticleUserNotificationObject;
 use wcf\system\user\notification\UserNotificationHandler;
 use wcf\system\user\object\watch\UserObjectWatchHandler;
@@ -153,6 +154,8 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                                'com.woltlab.wcf.article.notification',
                                new ArticleUserNotificationObject($article)
                        );
+                       
+                       UserActivityEventHandler::getInstance()->fireEvent('com.woltlab.wcf.article.recentActivityEvent', $article->articleID, null, $article->userID, $article->time);
                }
                
                return $article;
@@ -263,7 +266,7 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                
                $publicationStatus = (isset($this->parameters['data']['publicationStatus'])) ? $this->parameters['data']['publicationStatus'] : null;
                if ($publicationStatus !== null) {
-                       $usersToArticles = $resetNotifications = [];
+                       $usersToArticles = $resetArticleIDs = [];
                        /** @var ArticleEditor $articleEditor */
                        foreach ($this->objects as $articleEditor) {
                                if ($publicationStatus != $articleEditor->publicationStatus) {
@@ -284,16 +287,20 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                                                        'com.woltlab.wcf.article.notification',
                                                        new ArticleUserNotificationObject($articleEditor->getDecoratedObject())
                                                );
+                                               
+                                               UserActivityEventHandler::getInstance()->fireEvent('com.woltlab.wcf.article.recentActivityEvent', $articleEditor->articleID, null, $articleEditor->userID, $articleEditor->time);
                                        }
                                        else {
-                                               $resetNotifications[] = $articleEditor->articleID;
+                                               $resetArticleIDs[] = $articleEditor->articleID;
                                        }
                                }
                        }
                        
-                       if (!empty($resetNotifications)) {
+                       if (!empty($resetArticleIDs)) {
                                // delete user notifications
-                               UserNotificationHandler::getInstance()->removeNotifications('com.woltlab.wcf.article.notification', $resetNotifications);
+                               UserNotificationHandler::getInstance()->removeNotifications('com.woltlab.wcf.article.notification', $resetArticleIDs);
+                               // delete recent activity events
+                               UserActivityEventHandler::getInstance()->removeEvents('com.woltlab.wcf.article.recentActivityEvent', $resetArticleIDs);
                        }
                        
                        if (!empty($usersToArticles)) {
@@ -353,6 +360,8 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                        SearchIndexManager::getInstance()->delete('com.woltlab.wcf.article', $articleContentIDs);
                        // delete user notifications
                        UserNotificationHandler::getInstance()->removeNotifications('com.woltlab.wcf.article.notification', $articleIDs);
+                       // delete recent activity events
+                       UserActivityEventHandler::getInstance()->removeEvents('com.woltlab.wcf.article.recentActivityEvent', $articleIDs);
                }
                
                $this->unmarkItems();
@@ -648,6 +657,8 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                                'com.woltlab.wcf.article.notification',
                                new ArticleUserNotificationObject($articleEditor->getDecoratedObject())
                        );
+                       
+                       UserActivityEventHandler::getInstance()->fireEvent('com.woltlab.wcf.article.recentActivityEvent', $articleEditor->articleID, null, $articleEditor->userID, TIME_NOW);
                }
                
                ArticleEditor::updateArticleCounter($usersToArticles);
@@ -707,6 +718,9 @@ class ArticleAction extends AbstractDatabaseObjectAction {
                // delete user notifications
                UserNotificationHandler::getInstance()->removeNotifications('com.woltlab.wcf.article.notification', $articleIDs);
                
+               // delete recent activity events
+               UserActivityEventHandler::getInstance()->removeEvents('com.woltlab.wcf.article.recentActivityEvent', $articleIDs);
+               
                ArticleEditor::updateArticleCounter($usersToArticles);
                
                $this->unmarkItems();
diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ArticleUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ArticleUserActivityEvent.class.php
new file mode 100644 (file)
index 0000000..3f45280
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+namespace wcf\system\user\activity\event;
+use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * User activity event implementation for articles.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\User\Activity\Event
+ */
+class ArticleUserActivityEvent extends SingletonFactory implements IUserActivityEvent {
+       /**
+        * @inheritDoc
+        */
+       public function prepare(array $events) {
+               $objectIDs = [];
+               foreach ($events as $event) {
+                       $objectIDs[] = $event->objectID;
+               }
+               
+               ViewableArticleRuntimeCache::getInstance()->cacheObjectIDs($objectIDs);
+               
+               // set message
+               foreach ($events as $event) {
+                       $article = ViewableArticleRuntimeCache::getInstance()->getObject($event->objectID);
+                       if ($article !== null) {
+                               if ($article->canRead()) {
+                                       $event->setIsAccessible();
+                                       
+                                       $text = WCF::getLanguage()->getDynamicVariable('wcf.article.recentActivity', ['article' => $article]);
+                                       $event->setTitle($text);
+                                       $event->setDescription($article->getFormattedTeaser());
+                               }
+                       }
+                       else {
+                               $event->setIsOrphaned();
+                       }
+               }
+       }
+}
index 987c245ba66b1dd94803ca633b09b56da4c974af..95458d5276455f6f6042ab5a0bbf018fa2c9b525 100644 (file)
@@ -2396,6 +2396,7 @@ Benutzerkontos nun in vollem Umfang nutzen.]]></item>
                <item name="wcf.article.sortField.views"><![CDATA[Zugriffe]]></item>
                <item name="wcf.article.markAllAsRead"><![CDATA[Alle Artikel als gelesen markieren]]></item>
                <item name="wcf.article.showArticlesWritten"><![CDATA[Artikel von {$user->username}]]></item>
+               <item name="wcf.article.recentActivity"><![CDATA[Hat den Artikel <a href="{$article->getLink()}">{$article->getTitle()}</a> verfasst.]]></item>
        </category>
        
        <category name="wcf.attachment">
@@ -3986,6 +3987,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.recentActivity.com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived"><![CDATA[Trophäe]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.page.recentActivityEvent"><![CDATA[Kommentar (Seite)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.page.response.recentActivityEvent"><![CDATA[Antwort (Seite)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.article.recentActivityEvent"><![CDATA[Artikel]]></item>
                <item name="wcf.user.recentActivity.condition.excludedObjectType"><![CDATA[Ausgeschlossene Aktivitäten]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[Aktivitäten aller Benutzer]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Aktivitäten von Benutzern, denen {if LANGUAGE_USE_INFORMAL_VARIANT}du folgst{else}Sie folgen{/if}]]></item>
index e52586745dae05bba719c3dd5e49e260607c53a0..3481c4c6ab070bcf7291579e9657379a2713f2c3 100644 (file)
@@ -2333,6 +2333,7 @@ full extend.]]></item>
                <item name="wcf.article.sortField.views"><![CDATA[Views]]></item>
                <item name="wcf.article.markAllAsRead"><![CDATA[Mark All Articles as Read]]></item>
                <item name="wcf.article.showArticlesWritten"><![CDATA[Articles by {$user->username}]]></item>
+               <item name="wcf.article.recentActivity"><![CDATA[Wrote the article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
        </category>
        
        <category name="wcf.attachment">
@@ -3981,6 +3982,7 @@ Open the link below to access the user profile:
                <item name="wcf.user.recentActivity.com.woltlab.wcf.userTrophy.recentActivityEvent.trophyReceived"><![CDATA[Trophy]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.page.recentActivityEvent"><![CDATA[Comment (Page)]]></item>
                <item name="wcf.user.recentActivity.com.woltlab.wcf.page.response.recentActivityEvent"><![CDATA[Reply (Page)]]></item>
+               <item name="wcf.user.recentActivity.com.woltlab.wcf.article.recentActivityEvent"><![CDATA[Article]]></item>
                <item name="wcf.user.recentActivity.condition.excludedObjectType"><![CDATA[Excluded Activities]]></item>
                <item name="wcf.user.recentActivity.scope.all"><![CDATA[All Activities]]></item>
                <item name="wcf.user.recentActivity.scope.followedUsers"><![CDATA[Filter by Followed Users]]></item>