Ejemplo n.º 1
0
 /**
  * Duplicates the category article associations from one category to another
  *
  * @param int $originalCategoryId
  * @param int $newCategoryId
  */
 public function duplicateCategoryArticleAssociations($originalCategoryId, $newCategoryId)
 {
     $assocArticlesStmt = $this->connection->prepare('SELECT articleID FROM s_articles_categories WHERE categoryID = :categoryID');
     $assocArticlesStmt->execute([':categoryID' => $originalCategoryId]);
     $articles = $assocArticlesStmt->fetchAll(\PDO::FETCH_COLUMN, 0);
     if ($articles) {
         $insertStmt = $this->connection->prepare("INSERT INTO s_articles_categories (categoryID, articleID)\n            VALUES (" . $newCategoryId . ", " . implode($articles, "), (" . $newCategoryId . ", ") . ")");
         $insertStmt->execute();
         foreach ($articles as $articleId) {
             $this->categoryDenormalization->addAssignment($articleId, $newCategoryId);
         }
     }
 }
 public function testRemoveArticleAssignmentments()
 {
     // Assign to Getränke
     $this->conn->exec('INSERT INTO s_articles_categories (articleID, categoryID) VALUES (1, 5)');
     $this->component->addAssignment(1, 5);
     // Assign to Spirits
     $this->conn->exec('INSERT INTO s_articles_categories (articleID, categoryID) VALUES (1, 7)');
     $this->component->addAssignment(1, 7);
     // Assign to Spirits
     $this->conn->exec('INSERT INTO s_articles_categories (articleID, categoryID) VALUES (1, 7)');
     $this->component->addAssignment(2, 7);
     $affectedRows = $this->component->removeArticleAssignmentments(1);
     $this->assertEquals(6, $affectedRows);
     $this->assertEquals(3, $this->getConnection()->getRowCount('s_articles_categories_ro'));
 }