Skip to content

Commit

Permalink
added LINK_SCANNER_TARGET constant
Browse files Browse the repository at this point in the history
  • Loading branch information
mirko-pagliai committed Sep 21, 2018
1 parent b048cda commit 0cf729d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
17 changes: 15 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@
define('LINK_SCANNER_LOCK_FILE', TMP . 'link_scanner_lock_file');
}

//Sets the path where to export results
if (!defined('LINK_SCANNER_TARGET')) {
define('LINK_SCANNER_TARGET', TMP . 'link-scanner');
}

if (!file_exists(LINK_SCANNER_TARGET)) {
safe_mkdir(LINK_SCANNER_TARGET);
}

if (!is_writeable(LINK_SCANNER_TARGET)) {
trigger_error(sprintf('Directory %s not writeable', LINK_SCANNER_TARGET), E_USER_ERROR);
}

if (!Cache::getConfig(LINK_SCANNER)) {
Cache::setConfig(LINK_SCANNER, [
'className' => 'File',
'duration' => '+1 day',
'path' => CACHE . 'link_scanner',
'prefix' => null,
'path' => CACHE,
'prefix' => 'link_scanner_',
]);
}
6 changes: 3 additions & 3 deletions src/Utility/LinkScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ public function export($filename = null)
}

try {
$filename = $filename ?: TMP . sprintf('results_%s_%s', $this->hostname, $this->startTime);
$filename = Folder::isAbsolute($filename) ? $filename : TMP . $filename;
$filename = $filename ?: sprintf('results_%s_%s', $this->hostname, $this->startTime);
$filename = Folder::isAbsolute($filename) ? $filename : LINK_SCANNER_TARGET . DS . $filename;
file_put_contents($filename, serialize($this));
} catch (Exception $e) {
$message = preg_replace('/^file_put_contents\([\/\w\d:\-\\\\]+\): /', null, $e->getMessage());
Expand Down Expand Up @@ -256,7 +256,7 @@ public function export($filename = null)
public static function import($filename)
{
try {
$filename = Folder::isAbsolute($filename) ? $filename : TMP . $filename;
$filename = Folder::isAbsolute($filename) ? $filename : LINK_SCANNER_TARGET . DS . $filename;
$instance = unserialize(file_get_contents($filename));
} catch (Exception $e) {
$message = preg_replace('/^file_get_contents\([\/\w\d:\-\\\\]+\): /', null, $e->getMessage());
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Shell/LinkScannerShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function testScanParams()

$this->assertEventFired(LINK_SCANNER . '.resultsExported', $this->EventManager);

$expectedExportFile = TMP . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;
$expectedExportFile = LINK_SCANNER_TARGET . DS . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime;
$this->assertFileExists($expectedExportFile);

$messages = $this->out->messages();
Expand All @@ -207,8 +207,8 @@ public function testScanParams()
$this->assertEquals($params['timeout'], $this->LinkScanner->Client->getConfig('timeout'));

foreach ([
'example' => TMP . 'example',
sys_get_temp_dir() . DS . 'example' => sys_get_temp_dir() . DS . 'example',
'example' => LINK_SCANNER_TARGET . DS . 'example',
TMP . 'example' => TMP . 'example',
] as $filename => $expectedExportFile) {
$this->LinkScannerShell = $this->getLinkScannerShell();
$this->LinkScannerShell->params = ['export' => $filename] + $params;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Utility/LinkScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public function testExport()

//Filename can be `null`, relative or absolute
foreach ([
null => TMP . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime,
'example' => TMP . 'example',
null => LINK_SCANNER_TARGET . DS . 'results_' . $this->LinkScanner->hostname . '_' . $this->LinkScanner->startTime,
'example' => LINK_SCANNER_TARGET . DS . 'example',
TMP . 'example' => TMP . 'example',
] as $filenameWhereToExport => $expectedFilename) {
$result = $this->LinkScanner->export($filenameWhereToExport);
Expand Down
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
define('APP_DIR', 'TestApp');
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', APP . 'webroot' . DS);
define('TMP', sys_get_temp_dir() . DS . 'cakephp-link-scanner' . DS . 'tmp' . DS);
define('CACHE', sys_get_temp_dir() . DS . 'cakephp-link-scanner' . DS . 'cache' . DS);
define('TMP', sys_get_temp_dir() . DS . 'cakephp-link-scanner' . DS);
define('CACHE', TMP . 'cache' . DS);
define('CONFIG', APP . 'config' . DS);
define('LOGS', TMP);
define('SESSIONS', TMP . 'sessions' . DS);

safe_mkdir(sys_get_temp_dir() . DS . 'cakephp-link-scanner');
safe_mkdir(TMP);
safe_mkdir(LOGS);
safe_mkdir(SESSIONS);
Expand Down

0 comments on commit 0cf729d

Please sign in to comment.