Since: 0.1.0
Author: John Resig
Inheritance: extends Action
Exemplo n.º 1
0
    protected function purgeData($timestamp, $batchSize)
    {
        $date = swarmdb_dateformat($timestamp);
        // Based on ManageProjectScript::delete()
        $stats = array();
        $db = $this->getContext()->getDB();
        while (true) {
            $jobRows = $db->getRows(str_queryf('SELECT id
				FROM jobs
				WHERE created < %s
				LIMIT %u;', $date, $batchSize));
            if (!$jobRows) {
                // Done
                break;
            }
            $jobIDs = array_map(function ($row) {
                return $row->id;
            }, $jobRows);
            $this->out('...deleting ' . count($jobIDs) . ' jobs');
            $action = WipejobAction::newFromContext($this->getContext());
            $result = $action->doWipeJobs('delete', $jobIDs, $batchSize);
            $this->mergeStats($stats, $result);
        }
        // TODO: Purge rows from clients table for clients that are no
        // longer active and don't have 0 runresults after the purge.
        foreach ($stats as $key => $val) {
            $this->out("deleted {$key} rows: {$val}");
        }
        $this->out('');
        $this->out('Done!');
    }
Exemplo n.º 2
0
    public function delete()
    {
        $db = $this->getContext()->getDB();
        $projectID = $this->getOption('id');
        if (!$projectID) {
            $this->error('--id is required.');
        }
        // Ensure the project exists.
        $field = $db->getOne(str_queryf('SELECT id FROM projects WHERE id = %s;', $projectID));
        if (!$field) {
            $this->error('Project does not exist.');
        }
        $this->out("Are you sure you want to remove project '{$projectID}' and all associated jobs and runs? (Y/N)");
        $answer = $this->cliInput();
        if ($answer !== 'Y') {
            $this->error('Aborted.');
            return;
        }
        $batchSize = 100;
        $stats = array();
        while (true) {
            $jobRows = $db->getRows(str_queryf('SELECT id
				FROM jobs
				WHERE project_id = %s
				ORDER BY id
				LIMIT %u;', $projectID, $batchSize));
            if (!$jobRows) {
                // Done
                break;
            }
            $jobIDs = array_map(function ($row) {
                return $row->id;
            }, $jobRows);
            $this->out('...deleting ' . count($jobIDs) . ' jobs');
            $action = WipejobAction::newFromContext($this->getContext());
            $result = $action->doWipeJobs('delete', $jobIDs, $batchSize);
            $this->mergeStats($stats, $result);
        }
        foreach ($stats as $key => $val) {
            $this->out("deleted {$key} rows: {$val}");
        }
        $this->out('');
        $this->out('...deleting project credentials');
        $db->query(str_queryf('DELETE FROM projects WHERE id = %s;', $projectID));
        $this->out('project has been deleted.');
        $this->out('');
        $this->out('Done!');
    }