InvalidatePageController::invalidatePageAction()   A
last analyzed

Complexity

Conditions 6
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.0444
c 0
b 0
f 0
cc 6
nc 2
nop 0
1
<?php
2
3
namespace ExpressApi\V1\Rpc\InvalidatePage;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
7
class InvalidatePageController extends AbstractActionController {
8
9
    public function invalidatePageAction() {
10
        $response = array(
11
            'success' => false
12
        );
13
        $pageId = (int) $this->params()->fromRoute('page_id');
14
        $pagesDir = $this->getPagesPath();
15
        if($pageId > 0 && is_dir($pagesDir)) {
16
            $dirContent = scandir($pagesDir);
17
            foreach($dirContent as $languageDir) {
18
                $filename = $pagesDir.$languageDir.'/'.$pageId.'.html';
19
                if(file_exists($filename) && is_file($filename)){
20
                    unlink($filename);
21
                }
22
            }
23
            $response['success'] = true;
24
        }
25
        return $response;
26
    }
27
28
    private function getPagesPath() {
29
        $config = $this->getServiceLocator()->get('Config');
30
        if(is_array($config) &&
31
                isset($config['template_assets_resolver']) &&
32
                isset($config['template_assets_resolver']['public_path'])) {
33
            return $config['template_assets_resolver']['public_path'].'pages'.DIRECTORY_SEPARATOR;
34
        }
35
        return '';
36
    }
37
}
38