Adding method to mark all given pageid as offline

parent 5aed1196
......@@ -101,4 +101,15 @@ class CachePageDecorator extends BaseCacheDecorator implements PageRepository
$this->markAsOnlineInAllLocales($pageId);
}
/**
* @param int $pageId
* @return mixed
*/
public function markAsOfflineInAllLocales(int $pageId)
{
$this->clearCache();
$this->markAsOfflineInAllLocales($pageId);
}
}
......@@ -188,4 +188,20 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
return $this->update($page, $data);
}
/**
* @param int $pageId
* @return mixed
*/
public function markAsOfflineInAllLocales(int $pageId)
{
$page = $this->find($pageId);
$data = [];
foreach (app(LaravelLocalization::class)->getSupportedLocales() as $locale => $supportedLocale) {
$data[$locale] = ['status' => 0];
}
return $this->update($page, $data);
}
}
......@@ -39,4 +39,10 @@ interface PageRepository extends BaseRepository
* @return mixed
*/
public function markAsOnlineInAllLocales(int $pageId);
/**
* @param int $pageId
* @return mixed
*/
public function markAsOfflineInAllLocales(int $pageId);
}
......@@ -199,6 +199,17 @@ class EloquentPageRepositoryTest extends BasePageTest
$this->assertTrue($page->translate('fr')->status);
}
/** @test */
public function it_can_mark_page_as_offline_in_all_locales()
{
$page = $this->createRandomOnlinePage();
$page = $this->page->markAsOfflineInAllLocales($page->id);
$this->assertFalse($page->translate('en')->status);
$this->assertFalse($page->translate('fr')->status);
}
private function createPage()
{
return $this->page->create([
......@@ -235,4 +246,28 @@ class EloquentPageRepositoryTest extends BasePageTest
return $this->page->create($data);
}
private function createRandomOnlinePage()
{
$faker = \Faker\Factory::create();
$data = [
'is_home' => 0,
'template' => 'default',
'en' => [
'status' => 1,
'title' => $faker->name,
'slug' => $faker->slug,
'body' => $faker->paragraph(),
],
'fr' => [
'status' => 1,
'title' => $faker->name,
'slug' => $faker->slug,
'body' => $faker->paragraph(),
],
];
return $this->page->create($data);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment