diff --git a/modules/cms/classes/AutoDatasource.php b/modules/cms/classes/AutoDatasource.php index 4428620c00..7b3a289c75 100644 --- a/modules/cms/classes/AutoDatasource.php +++ b/modules/cms/classes/AutoDatasource.php @@ -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); @@ -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']) { @@ -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); @@ -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; @@ -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) { @@ -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); } @@ -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); diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index ed22d6b4c2..da9c8d18f2 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -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; } @@ -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) { diff --git a/modules/system/tests/plugins/database/NestedTreeModelTest.php b/modules/system/tests/plugins/database/NestedTreeModelTest.php index e533a8b319..1621da5170 100644 --- a/modules/system/tests/plugins/database/NestedTreeModelTest.php +++ b/modules/system/tests/plugins/database/NestedTreeModelTest.php @@ -3,7 +3,6 @@ namespace System\Tests\Plugins\Database; use System\Tests\Bootstrap\PluginTestCase; -use Carbon\Carbon; use Database\Tester\Models\CategoryNested; use Model; @@ -58,6 +57,8 @@ public function testListsNested() 9 => '   Spring Trees' ], $array); + CategoryNested::flushDuplicateCache(); + $array = CategoryNested::listsNested('name', 'id', '--'); $this->assertEquals([ 1 => 'Category Orange', @@ -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', @@ -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.' ]);