-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tagging: move mimetype to metadata, add location/orphan tag source
- Loading branch information
1 parent
87327fc
commit a106f24
Showing
12 changed files
with
198 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
namespace tool_objectfs\local\tag; | ||
|
||
/** | ||
* Provides environment a file was uploaded in. | ||
* Provides current environment to file. | ||
* | ||
* @package tool_objectfs | ||
* @author Matthew Hilton <[email protected]> | ||
|
@@ -53,7 +53,7 @@ private static function get_env(): ?string { | |
/** | ||
* Returns the tag value for the given file contenthash | ||
* @param string $contenthash | ||
* @return string|null mime type for file. | ||
* @return string|null environment value. | ||
*/ | ||
public function get_value_for_contenthash(string $contenthash): ?string { | ||
return self::get_env(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,28 +17,28 @@ | |
namespace tool_objectfs\local\tag; | ||
|
||
/** | ||
* Provides mime type of file. | ||
* Provides location status for a file. | ||
* | ||
* @package tool_objectfs | ||
* @author Matthew Hilton <[email protected]> | ||
* @copyright Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class mime_type_source implements tag_source { | ||
class location_source implements tag_source { | ||
/** | ||
* Identifier used in tagging file. Is the 'key' of the tag. | ||
* @return string | ||
*/ | ||
public static function get_identifier(): string { | ||
return 'mimetype'; | ||
return 'location'; | ||
} | ||
|
||
/** | ||
* Description for source displayed in the admin settings. | ||
* @return string | ||
*/ | ||
public static function get_description(): string { | ||
return get_string('tagsource:mimetype', 'tool_objectfs'); | ||
return get_string('tagsource:location', 'tool_objectfs'); | ||
} | ||
|
||
/** | ||
|
@@ -48,18 +48,10 @@ public static function get_description(): string { | |
*/ | ||
public function get_value_for_contenthash(string $contenthash): ?string { | ||
global $DB; | ||
// Sometimes multiple with same hash are uploaded (e.g. real vs draft), | ||
// in this case, just take the first (mimetype is the same regardless). | ||
$mime = $DB->get_field_sql('SELECT mimetype | ||
FROM {files} | ||
WHERE contenthash = :hash | ||
LIMIT 1', | ||
['hash' => $contenthash]); | ||
|
||
if (empty($mime)) { | ||
return null; | ||
} | ||
$isorphaned = $DB->record_exists('tool_objectfs_objects', ['contenthash' => $contenthash, | ||
'location' => OBJECT_LOCATION_ORPHANED]); | ||
|
||
return $mime; | ||
return $isorphaned ? 'orphan' : 'active'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.