Commit 3df7f98c authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1597536: cleaning up old import_entry_requests rows



And avoiding storing full path to dataroot temp dir in db for imported
entries

behatnotneeded

Change-Id: I18fb3a76accd57517e340ce98a19f7b10bd4814c
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 1b7d9ad2
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -377,11 +377,13 @@ class LeapImportFile extends LeapImportArtefactPlugin {
        $data = self::get_file_entry_data($entry, $importer, $parent);

        $pathname = $data->pathname;

        if (file_exists($pathname)) {
            $filesize = filesize($pathname);
        }

        // Don't save full pathname to db, only the relative path to dataroot
        $pathname = preg_replace('#^' . get_config('dataroot') . '#', '', $pathname);

        // Work around that save_file doesn't let us set the mtime
        return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string)$entry->id, self::STRATEGY_IMPORT_AS_FILE, 'file', array(
            'owner'   => $data->owner,
@@ -417,7 +419,7 @@ class LeapImportFile extends LeapImportArtefactPlugin {
                $data->parent = $parent;
            }
            $data->owner = $entry_request->ownerid;

            $data->pathname = get_config('dataroot') . $data->pathname;
            if ($artefact = self::create_file_from_entry_data($data, $importer, $entry_request->entryid)) {
                $importer->add_artefactmapping($entry_request->entryid, $artefact->get('id'), true);
                return $artefact;
+17 −11
Original line number Diff line number Diff line
@@ -295,6 +295,7 @@ abstract class PluginImport extends Plugin implements IPluginImport {
                'duplicateditemids' => serialize($duplicatedartefactids),
                'existingitemids'   => serialize($existingartefactids),
                'decision'   => $decision,
                'ctime' => db_format_timestamp(time()),
            ));
        }
        return false;
@@ -685,15 +686,19 @@ class MnetImporterTransport extends ImporterTransport {
/**
 * Looks in the import staging area in dataroot and deletes old, unneeded
 * import.
 * Also cleans up old import entries in the 'import_entry_requests' table
 */
function import_cleanup_old_imports() {
    require_once('file.php');
    $mintime = time() - (12 * 60 * 60); // delete imports older than 12 hours

    // remove entries from db older than 12 hours
    delete_records_select('import_entry_requests', 'ctime < ?', array(db_format_timestamp($mintime)));

    // Delete old files from the import staging area in dataroot
    $basedir = get_config('dataroot') . 'import/';
    if (!check_dir_exists($basedir, false)) {
        return;
    }
    if (check_dir_exists($basedir, false)) {
        $importdir = new DirectoryIterator($basedir);
    $mintime = time() - (12 * 60 * 60); // delete imports older than 12 hours

        // The import dir contains one directory for each attempted import, named
        // after their username and the import timestamp
@@ -704,3 +709,4 @@ function import_cleanup_old_imports() {
            }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -1035,6 +1035,7 @@
                <FIELD NAME="existingitemids" TYPE="text" NOTNULL="false" />
                <FIELD NAME="artefactmapping" TYPE="text" NOTNULL="false" />
                <FIELD NAME="decision" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
                <FIELD NAME="ctime" TYPE="datetime" NOTNULL="false" />
            </FIELDS>
            <KEYS>
                <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+12 −0
Original line number Diff line number Diff line
@@ -4200,5 +4200,17 @@ function xmldb_core_upgrade($oldversion=0) {
        set_field('usr', 'suspendedcusr', $suspendinguserid, 'suspendedcusr', 0);
    }

    if ($oldversion < 2015030438) {
        log_debug('Add a "ctime" column to import_entry_requests table.');
        $table = new XMLDBTable('import_entry_requests');
        $field = new XMLDBField('ctime');
        $field->setAttributes(XMLDB_TYPE_DATETIME);
        if (!field_exists($table, $field)) {
            add_field($table, $field);
            // Fill in starting value for existing rows.
            execute_sql('UPDATE {import_entry_requests} SET ctime = ?', array(db_format_timestamp(time())));
        }
    }

    return $status;
}
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one.  On master, use the date.

$config->version = 2015030437;
$config->version = 2015030438;
$config->series = '15.04';
$config->release = '15.04.10testing';
$config->minupgradefrom = 2009022600;