Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Utils / Create / CommentData.php
index 1a6b9cca828266152ff708b017fa5fdfaa00a2a2..3d9a1f8d6d3c40abb205dfec8b1c48d737655ff8 100644 (file)
@@ -18,25 +18,6 @@ use Drupal\Core\Datetime\DateFormatterInterface;
  */
 class CommentData extends Base
 {
-    /**
-     * Comments constructor.
-     *
-     * @param EntityTypeManagerInterface  $entityTypeManager
-     * @param EntityFieldManagerInterface $entityFieldManager
-     * @param DateFormatterInterface      $dateFormatter
-     */
-    public function __construct(
-        EntityTypeManagerInterface $entityTypeManager,
-        EntityFieldManagerInterface $entityFieldManager,
-        DateFormatterInterface $dateFormatter
-    ) {
-        parent::__construct(
-            $entityTypeManager,
-            $entityFieldManager,
-            $dateFormatter
-        );
-    }
-
     /**
      * @param $nid
      * @param $limit
@@ -53,24 +34,24 @@ class CommentData extends Base
     ) {
         $comments = [];
 
-        for ($i=0; $i<$limit; $i++) {
-            $comment = $this->entityTypeManager->getStorage('comment')->create(
-                [
-                'entity_id' => $nid,
-                'entity_type' => 'node',
-                'field_name' => 'comment',
-                'created' => REQUEST_TIME - mt_rand(0, $timeRange),
-                'uid' => $this->getUserID(),
-                'status' => true,
-                'subject' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
-                'language' => 'und',
-                'comment_body' => ['und' => ['random body']],
-                ]
-            );
+        for ($i = 0; $i < $limit; $i++) {
+            try {
+                $comment = $this->entityTypeManager->getStorage('comment')->create(
+                    [
+                        'entity_id' => $nid,
+                        'entity_type' => 'node',
+                        'field_name' => 'comment',
+                        'created' => REQUEST_TIME - mt_rand(0, $timeRange),
+                        'uid' => $this->getUserID(),
+                        'status' => true,
+                        'subject' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
+                        'language' => 'und',
+                        'comment_body' => ['und' => ['random body']],
+                    ]
+                );
 
-            $this->generateFieldSampleData($comment);
+                $this->generateFieldSampleData($comment);
 
-            try {
                 $comment->save();
                 $comments['success'][] = [
                     'nid' => $nid,
@@ -80,13 +61,10 @@ class CommentData extends Base
                         $comment->getCreatedTime(),
                         'custom',
                         'Y-m-d h:i:s'
-                    )
+                    ),
                 ];
             } catch (\Exception $error) {
-                $comments['error'][] = [
-                    'title' => $comment->getTitle(),
-                    'error' => $error->getMessage()
-                ];
+                $comments['error'][] = $error->getMessage();
             }
         }