Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 25 additions & 69 deletions modules/cms/classes/AutoDatasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,9 @@ protected function getActiveDatasource()
}

/**
* Returns a single template.
*
* @param string $dirName
* @param string $fileName
* @param string $extension
* @return mixed
* @inheritDoc
*/
public function selectOne(string $dirName, string $fileName, string $extension)
public function selectOne(string $dirName, string $fileName, string $extension): ?array
{
try {
$path = $this->makeFilePath($dirName, $fileName, $extension);
Expand Down Expand Up @@ -359,20 +354,9 @@ public function selectOne(string $dirName, string $fileName, string $extension)
}

/**
* Returns all templates.
*
* @param string $dirName
* @param array $options Array of options, [
* 'columns' => ['fileName', 'mtime', 'content'], // Only return specific columns
* 'extensions' => ['htm', 'md', 'twig'], // Extensions to search for
* 'fileMatch' => '*gr[ae]y', // Shell matching pattern to match the filename against using the fnmatch function
* 'orders' => false // Not implemented
* 'limit' => false // Not implemented
* 'offset' => false // Not implemented
* ];
* @return array
* @inheritDoc
*/
public function select(string $dirName, array $options = [])
public function select(string $dirName, array $options = []): array
{
// Handle fileName listings through just the cache
if (@$options['columns'] === ['fileName']) {
Expand Down Expand Up @@ -412,15 +396,9 @@ public function select(string $dirName, array $options = [])
}

/**
* Creates a new template, only inserts to the active datasource
*
* @param string $dirName
* @param string $fileName
* @param string $extension
* @param string $content
* @return bool
* @inheritDoc
*/
public function insert(string $dirName, string $fileName, string $extension, string $content)
public function insert(string $dirName, string $fileName, string $extension, string $content): int
{
// Insert only on the active datasource
$result = $this->getActiveDatasource()->insert($dirName, $fileName, $extension, $content);
Expand All @@ -432,17 +410,9 @@ public function insert(string $dirName, string $fileName, string $extension, str
}

/**
* Updates an existing template.
*
* @param string $dirName
* @param string $fileName
* @param string $extension
* @param string $content
* @param string $oldFileName Defaults to null
* @param string $oldExtension Defaults to null
* @return int
* @inheritDoc
*/
public function update(string $dirName, string $fileName, string $extension, string $content, $oldFileName = null, $oldExtension = null)
public function update(string $dirName, string $fileName, string $extension, string $content, $oldFileName = null, $oldExtension = null): int
{
$searchFileName = $oldFileName ?: $fileName;
$searchExt = $oldExtension ?: $extension;
Expand Down Expand Up @@ -470,21 +440,16 @@ public function update(string $dirName, string $fileName, string $extension, str
}

/**
* Run a delete statement against the datasource, only runs delete on active datasource
*
* @param string $dirName
* @param string $fileName
* @param string $extension
* @return int
* @inheritDoc
*/
public function delete(string $dirName, string $fileName, string $extension)
public function delete(string $dirName, string $fileName, string $extension): bool
{
try {
// Delete from only the active datasource
if ($this->forceDeleting) {
$this->getActiveDatasource()->forceDelete($dirName, $fileName, $extension);
$success = $this->getActiveDatasource()->forceDelete($dirName, $fileName, $extension);
} else {
$this->getActiveDatasource()->delete($dirName, $fileName, $extension);
$success = $this->getActiveDatasource()->delete($dirName, $fileName, $extension);
}
}
catch (Exception $ex) {
Expand All @@ -501,7 +466,7 @@ public function delete(string $dirName, string $fileName, string $extension)
$this->insert($dirName, $fileName, $extension, $record['content']);

// Perform the deletion on the newly inserted record
$this->delete($dirName, $fileName, $extension);
$success = $this->delete($dirName, $fileName, $extension);
} else {
throw (new DeleteFileException)->setInvalidPath($path);
}
Expand All @@ -510,54 +475,45 @@ public function delete(string $dirName, string $fileName, string $extension)

// Refresh the cache
$this->populateCache(true);

return $success;
}

/**
* Return the last modified date of an object
*
* @param string $dirName
* @param string $fileName
* @param string $extension
* @return int
* @inheritDoc
*/
public function lastModified(string $dirName, string $fileName, string $extension)
public function lastModified(string $dirName, string $fileName, string $extension): int
{
return $this->getDatasourceForPath($this->makeFilePath($dirName, $fileName, $extension))->lastModified($dirName, $fileName, $extension);
}

/**
* Generate a cache key unique to this datasource.
*
* @param string $name
* @return string
* @inheritDoc
*/
public function makeCacheKey($name = '')
public function makeCacheKey($name = ''): string
{
$key = '';

foreach ($this->datasources as $datasource) {
$key .= $datasource->makeCacheKey($name) . '-';
}
$key .= $name;

return crc32($key);
return hash('crc32b', $key);
}

/**
* Generate a paths cache key unique to this datasource
*
* @return string
* @inheritDoc
*/
public function getPathsCacheKey()
public function getPathsCacheKey(): string
{
return 'halcyon-datastore-auto';
}

/**
* Get all available paths within this datastore
*
* @return array $paths ['path/to/file1.md' => true (path can be handled and exists), 'path/to/file2.md' => false (path can be handled but doesn't exist)]
* @inheritDoc
*/
public function getAvailablePaths()
public function getAvailablePaths(): array
{
$paths = [];
$datasources = array_reverse($this->datasources);
Expand Down
4 changes: 2 additions & 2 deletions modules/system/classes/CombineAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected function prepareCombiner(array $assets, $rewritePath = null)
$filesSalt = null;
foreach ($assets as $asset) {
$filters = $this->getFilters(File::extension($asset)) ?: [];
$path = file_exists($asset) ? $asset : (File::symbolizePath($asset, null) ?: $this->localPath . $asset);
$path = file_exists($asset) ? $asset : (File::symbolizePath($asset, false) ?: $this->localPath . $asset);
$files[] = new FileAsset($path, $filters, public_path());
$filesSalt .= $this->localPath . $asset;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ protected function getDeepHashFromAssets($assets)
$key = '';

$assetFiles = array_map(function ($file) {
return file_exists($file) ? $file : (File::symbolizePath($file, null) ?: $this->localPath . $file);
return file_exists($file) ? $file : (File::symbolizePath($file, false) ?: $this->localPath . $file);
}, $assets);

foreach ($assetFiles as $file) {
Expand Down
7 changes: 5 additions & 2 deletions modules/system/tests/plugins/database/NestedTreeModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace System\Tests\Plugins\Database;

use System\Tests\Bootstrap\PluginTestCase;
use Carbon\Carbon;
use Database\Tester\Models\CategoryNested;
use Model;

Expand Down Expand Up @@ -58,6 +57,8 @@ public function testListsNested()
9 => '   Spring Trees'
], $array);

CategoryNested::flushDuplicateCache();

$array = CategoryNested::listsNested('name', 'id', '--');
$this->assertEquals([
1 => 'Category Orange',
Expand All @@ -71,6 +72,8 @@ public function testListsNested()
9 => '--Spring Trees'
], $array);

CategoryNested::flushDuplicateCache();

$array = CategoryNested::listsNested('description', 'name', '**');
$this->assertEquals([
'Category Orange' => 'A root level test category',
Expand Down Expand Up @@ -120,7 +123,7 @@ public function seedSampleTree()
'description' => 'The start of the fall season.'
]);

$october = $autumn->children()->create([
$autumn->children()->create([
'name' => 'October',
'description' => 'The middle of the fall season.'
]);
Expand Down