Parcourir la source

new confg object for storing data relating to update of feed

logicp il y a 7 ans
Parent
commit
cd9df2aab1
4 fichiers modifiés avec 40 ajouts et 2 suppressions
  1. 1 0
      heartbeat.module
  2. 1 1
      heartbeat.services.yml
  3. 26 0
      src/Ajax/UpdateFeedCommand.php
  4. 12 1
      src/HeartbeatStreamServices.php

+ 1 - 0
heartbeat.module

@@ -246,6 +246,7 @@ function heartbeat_handle_entity($entity, $tokenService, $heartbeatTypeService,
       }
     }
   }
+  \Drupal::service('config.factory')->getEditable('heartbeat_update_feed.settings')->set('update', true)->save();
 }
 
 

+ 1 - 1
heartbeat.services.yml

@@ -5,7 +5,7 @@ services:
 
   heartbeatstream:
     class: Drupal\heartbeat\HeartbeatStreamServices
-    arguments: ["@entity_type.manager", "@entity_type.repository", '@entity.query']
+    arguments: ["@entity_type.manager", "@entity_type.repository", '@entity.query', '@config.factory']
 
   heartbeatstreamalt:
     class: Drupal\heartbeat\HeartbeatAltServices

+ 26 - 0
src/Ajax/UpdateFeedCommand.php

@@ -0,0 +1,26 @@
+<?php
+namespace Drupal\heartbeat\Ajax;
+/**
+ * Created by IntelliJ IDEA.
+ * User: logicp
+ * Date: 5/28/17
+ * Time: 11:38 PM
+ */
+
+use Drupal\Core\Ajax\CommandInterface;
+
+class UpdateFeedCommand implements CommandInterface {
+    protected $message;
+
+    public function __construct($message) {
+        $this->message = $message;
+    }
+
+    public function render() {
+
+        return array(
+            'command' => 'selectFeed',
+            'feed' => $this->message
+        );
+    }
+}

+ 12 - 1
src/HeartbeatStreamServices.php

@@ -5,6 +5,7 @@ namespace Drupal\heartbeat;
 use Drupal\Core\Entity\EntityTypeManager;
 use Drupal\Core\Entity\EntityTypeRepository;
 use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\Core\Config\ConfigFactoryInterface;
 
 /**
  * Class HeartbeatStreamServices.
@@ -40,16 +41,24 @@ class HeartbeatStreamServices {
   protected $entityQuery;
 
 
+  /**
+   * The configuration factory.
+   *
+   * @var \Drupal\Core\Config\ConfigFactoryInterface
+   */
+  protected $configFactory;
+
   /**
    * Constructor.
    * @param EntityTypeManager $entityTypeManager
    * @param EntityTypeRepository $entityTypeRepository
    * @param QueryFactory $entityQuery
    */
-  public function __construct(EntityTypeManager $entityTypeManager, EntityTypeRepository $entityTypeRepository, QueryFactory $entityQuery) {
+  public function __construct(EntityTypeManager $entityTypeManager, EntityTypeRepository $entityTypeRepository, QueryFactory $entityQuery, ConfigFactoryInterface $configFactory) {
     $this->entityTypeManager = $entityTypeManager;
     $this->entityTypeRepository = $entityTypeRepository;
     $this->entityQuery = $entityQuery;
+    $this->configFactory = $configFactory;
   }
 
   /**
@@ -108,6 +117,8 @@ class HeartbeatStreamServices {
 
     $this->lastId = call_user_func('end', array_keys($beats));
 
+    $this->configFactory->getEditable('heartbeat_update_feed')->set('timestamp', $this->lastId)->set('update', false)->save();
+
     $this->latestTimestamp = array_values($beats)[0]->getRevisionCreationTime();
 
     return $beats;