saveContent() public méthode

Save a record.
public saveContent ( Content $content, string $comment = null ) : integer
$content Content
$comment string
Résultat integer
Exemple #1
0
 public function testSaveContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $storage = new Storage($app);
     // Test missing contenttype handled
     $content = new Content($app);
     $this->setExpectedException('Bolt\\Exception\\StorageException', 'Contenttype is required for saveContent');
     $this->assertFalse($storage->saveContent($content));
     // Test dispatcher is called pre-save and post-save
     $content = $storage->getContent('showcases/1');
     $presave = 0;
     $postsave = 0;
     $listener = function () use(&$presave) {
         $presave++;
     };
     $listener2 = function () use(&$postsave) {
         $postsave++;
     };
     $app['dispatcher']->addListener(StorageEvents::PRE_SAVE, $listener);
     $app['dispatcher']->addListener(StorageEvents::POST_SAVE, $listener2);
     $storage->saveContent($content);
     $this->assertEquals(1, $presave);
     $this->assertEquals(1, $postsave);
 }
Exemple #2
0
 public function testGetNextChangeLogEntry()
 {
     $app = $this->getApp();
     $app['config']->set('general/changelog/enabled', true);
     $storage = new Storage($app);
     // To generate an extra changelog we fetch and save a content item
     // For now we need to mock the request object.
     $app['request'] = Request::create('/');
     $content = $storage->getContent('pages/1');
     $this->assertInstanceOf('\\Bolt\\Legacy\\Content', $content);
     $content->setValues(['status' => 'draft', 'ownerid' => 99]);
     $storage->saveContent($content, 'Test Suite Update');
     $content->setValues(['status' => 'published', 'ownerid' => 1]);
     $storage->saveContent($content, 'Test Suite Update');
     $log = $this->getLogChangeRepository()->getChangeLogEntry('pages', 1, 1, '>');
     $this->assertAttributeEquals(1, 'contentid', $log);
 }
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $app['config']->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(['showcases', 'entries', 'pages']);
     // We also set some relations between showcases and entries
     $showcases = $storage->getContent('showcases');
     $randEntries = $storage->getContent('entries/random/2');
     foreach ($showcases as $show) {
         foreach (array_keys($randEntries) as $key) {
             $show->setRelation('entries', $key);
             $storage->saveContent($show);
         }
     }
     foreach ($randEntries as $entry) {
         $entry->setTaxonomy('categories', ['movies']);
         $storage->saveContent($entry);
     }
 }