Commit 42f487b1 authored by Penny Leach's avatar Penny Leach
Browse files

fixed bugs, remove debug code, fixed cron transfers

parent 9dda41d0
......@@ -91,7 +91,6 @@ class Client {
$xml = new SimpleXMLElement($this->rawresponse);
}
catch (Exception $e) {
log_debug($this->rawresponse);
throw new XmlrpcClientException('Payload is not a valid XML document (payload is above)', 6001);
}
......
......@@ -278,7 +278,7 @@ function send_content_intent($username) {
// check whatever config values we have to check
// generate a token, insert it into the queue table
$usequeue = 0; // @todo change this (check whatever)
$usequeue = 1; // @todo change this (check whatever)
$queue = new StdClass;
$queue->token = generate_token();
......@@ -305,7 +305,7 @@ function send_content_ready($token, $username, $format, $filesmanifest, $fetchno
// go verify the token
if (!$queue = get_record('import_queue', 'token', $token, 'host', $REMOTEWWWROOT)) {
throw new ImportException("Could not find queue record with token for username $username for $REMOTEWWWROOT");
throw new ImportException("Could not find queue record with given token for username $username for $REMOTEWWWROOT");
}
if (strtotime($queue->expirytime) < time()) {
......
......@@ -120,7 +120,6 @@ class User {
}
$this->populate($user);
log_debug("after populate, quota is " . $this->get('quota') . ' and used is ' . $this->get('quotaused'));
$this->reset_institutions();
$this->reset_grouproles();
return $this;
......@@ -429,7 +428,6 @@ class User {
}
public function quota_allowed($bytes) {
log_debug("testing for " . $this->get('quotaused') . ' + ' . $bytes . ' being > than ' . $this->get('quota'));
if ($this->get('quotaused') + $bytes > $this->get('quota')) {
return false;
}
......
......@@ -28,7 +28,7 @@ defined('INTERNAL') || die();
function import_process_queue() {
if (!$ready = get_records_array('import_queue',
'ready', 1, null, null, null, null,
'ready', 1, '',
'*,' . db_format_tsfield('expirytime', 'ex'))) {
return true;
}
......@@ -42,13 +42,14 @@ function import_process_queue() {
$processed[] = $item->id;
continue;
}
$importer = new MnetImporter($item->id, $item);
$importer = Importer::create_importer($item->id, $item);
try {
$importer->prepare();
$importer->process();
$processed[] = $item->id;
}
catch (Exception $e) {
$importer->cleanup();
$importer->get('importertransport')->cleanup();
}
}
......@@ -57,18 +58,12 @@ function import_process_queue() {
}
delete_records_select(
'incoming_queue',
'import_queue',
'id IN ( ' . implode(',', db_array_to_ph($processed)) . ')',
$processed
);
}
function import_file($queue) {
$importer = new MnetImporter($queue->id, $queue);
$importer->process();
}
abstract class Importer {
private $id;
......@@ -164,8 +159,9 @@ abstract class Importer {
throw new NotFoundException("Failed to find import queue record with id $id");
}
}
switch ($record->format) {
switch (trim($record->format)) {
case 'file':
case 'files':
return new FilesImporter($id, $record);
default:
// @todo more laterz (like mahara native and/or leap)
......@@ -234,8 +230,6 @@ class FilesImporter extends Importer {
$output = array();
exec($command, $output, $returnvar);
if ($returnvar != 0) {
log_debug($output);
log_debug("return var $returnvar");
throw new ImportException('Failed to unzip the file recieved from the transport object');
}
}
......@@ -303,7 +297,6 @@ class FilesImporter extends Importer {
if (empty($id)) {
throw new ImportException("Failed to create new artefact for $f->sha1");
}
log_debug('actually saved one!');
$savedfiles[] = $id;
}
catch (Exception $e) {
......@@ -314,9 +307,7 @@ class FilesImporter extends Importer {
throw new ImportException('Failed to create some new artefacts');
}
}
log_debug($savedfiles);
}
}
class MnetImporterTransport extends ImporterTransport {
......@@ -337,15 +328,23 @@ class MnetImporterTransport extends ImporterTransport {
}
public function cleanup() {
if (empty($this->tempdir)) {
return;
}
rmdir($this->tempdir);
}
public function prepare_files() {
require_once(get_config('docroot') . 'api/xmlrpc/client.php');
$client = new Client();
$client->set_method('portfolio/mahara/lib.php/fetch_file')
->add_param($this->token)
->send($this->host->wwwroot);
try {
$client->set_method('portfolio/mahara/lib.php/fetch_file')
->add_param($this->token)
->send($this->host->wwwroot);
} catch (XmlrpcClientException $e) {
log_debug($e);
throw new ImportException('Failed to retrieve zipfile from remote server');
}
if (!$filecontents = base64_decode($client->response)) {
throw new ImportException('Failed to retrieve zipfile from remote server');
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment