-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from keevan/440-add-archiver-task-to-handle-o…
…rphaned-objects Add archiver task to handle orphaned objects
- Loading branch information
Showing
19 changed files
with
465 additions
and
35 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
55 changes: 55 additions & 0 deletions
55
classes/local/object_manipulator/candidates/orphaner_candidates.php
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Class orphaner_candidates | ||
* @package tool_objectfs | ||
* @author Nathan Mares <[email protected]> | ||
* @copyright Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_objectfs\local\object_manipulator\candidates; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class orphaner_candidates extends manipulator_candidates_base { | ||
|
||
/** @var string $queryname */ | ||
protected $queryname = 'get_orphan_candidates'; | ||
|
||
/** | ||
* @inheritDoc | ||
* @return string | ||
*/ | ||
public function get_candidates_sql() { | ||
return 'SELECT o.id, o.contenthash, o.location | ||
FROM {tool_objectfs_objects} o | ||
LEFT JOIN {files} f ON o.contenthash = f.contenthash | ||
WHERE f.id is null | ||
AND o.location != :location'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @return array | ||
*/ | ||
public function get_candidates_sql_params() { | ||
return [ | ||
'location' => OBJECT_LOCATION_ORPHANED | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Orphans {tool_objectfs_objects} records for files that have been | ||
* deleted from the core {files} table. | ||
* | ||
* @package tool_objectfs | ||
* @author Nathan Mares <[email protected]> | ||
* @author Kevin Pham <[email protected]> | ||
* @copyright Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_objectfs\local\object_manipulator; | ||
|
||
use stdClass; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
class orphaner extends manipulator { | ||
|
||
/** | ||
* Updates the location of {tool_objectfs_objects} records for files that | ||
* have been deleted from the core {files} table. | ||
* | ||
* @param \stdClass $objectrecord | ||
* @return int | ||
*/ | ||
public function manipulate_object(stdClass $objectrecord): int { | ||
return OBJECT_LOCATION_ORPHANED; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Task that checks for old orphaned objects, and removes their metadata | ||
* (record) as it is no longer useful/relevant. | ||
* | ||
* @package tool_objectfs | ||
* @author Kevin Pham <[email protected]> | ||
* @copyright Catalyst IT | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_objectfs\task; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once(__DIR__ . '/../../lib.php'); | ||
|
||
class delete_orphaned_object_metadata extends task { | ||
|
||
/** @var string $stringname */ | ||
protected $stringname = 'delete_orphaned_object_metadata_task'; | ||
|
||
/** | ||
* Execute task | ||
*/ | ||
public function execute() { | ||
global $DB; | ||
|
||
$wheresql = 'location = :location and timeduplicated < :ageforremoval'; | ||
$ageforremoval = $this->config->maxorphanedage; | ||
if (empty($ageforremoval)) { | ||
mtrace('Skipping deletion of orphaned object metadata as maxorphanedage is set to an empty value.'); | ||
return; | ||
} | ||
|
||
$params = [ | ||
'location' => OBJECT_LOCATION_ORPHANED, | ||
'ageforremoval' => time() - $ageforremoval | ||
]; | ||
$count = $DB->count_records_select('tool_objectfs_objects', $wheresql, $params); | ||
if (!empty($count)) { | ||
mtrace("Deleting $count records with orphaned metadata (orphaned tool_objectfs_objects)"); | ||
$DB->delete_records_select('tool_objectfs_objects', $wheresql, $params); | ||
} | ||
} | ||
} |
Oops, something went wrong.