/** * Adds a new variable to lang. * * @param string $key Name of the variable * @param string $value Value of the variable * @throws Exception * @return boolean|null */ protected function set($key, $value) { try { if ($this->has($key)) { throw new Exception('Unable to set language string for <em>' . $key . '</em>. It was already set.'); } $this->_lang[$key] = $value; return true; } catch (Exception $e) { // @todo this should not be a fatal error ImportException::exception_handler($e); } }
} if (@ini_get('session.save_handler') == 'user') { @ini_set('session.save_handler', 'files'); } @session_start(); // Add slashes, as long as they aren't already being added. if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0) { $_POST = stripslashes_recursive($_POST); } $config = new Configurator(); $config->lang_dir = BASEDIR . '/Languages'; try { $lng = new Lang(); $lng->loadLang($config->lang_dir); } catch (Exception $e) { ImportException::exception_handler($e); } $template = new Template($lng); global $import; $importer = new Importer($config, $lng, $template); $response = new HttpResponse(new ResponseHeader()); $template->setResponse($response); $import = new ImportManager($config, $importer, $template, new Cookie(), $response); try { $import->process(); } catch (Exception $e) { // Debug, remember to remove before PR echo '<br>' . $e->getMessage() . '<br>'; echo $e->getFile() . '<br>'; echo $e->getLine() . '<br>'; // If an error is not catched, it means it's fatal and the script should die.
function send_content_ready($token, $username, $format, $importdata, $fetchnow = false) { global $REMOTEWWWROOT; require_once get_config('docroot') . 'import/lib.php'; list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT); if (!$user) { throw new ImportException(null, "Could not find user {$username} for {$REMOTEWWWROOT}"); } // go verify the token if (!($queue = get_record('import_queue', 'token', $token, 'host', $REMOTEWWWROOT))) { throw new ImportException(null, "Could not find queue record with given token for username {$username} for {$REMOTEWWWROOT}"); } if (strtotime($queue->expirytime) < time()) { throw new ImportException(null, "Queue record has expired"); } $class = null; try { $class = PluginImport::class_from_format($format); } catch (Exception $e) { throw new ImportException(null, "Invalid format {$format}"); } $queue->format = $format; if ($class == 'PluginImportLeap') { // don't import persondata over mnet // because it will just silently overwrite stuff // which is not really desirable. $queue->loglevel = get_config('leapovermnetloglevel'); $importdata['skippersondata'] = true; } $queue->data = serialize($importdata); update_record('import_queue', $queue); $tr = new MnetImporterTransport($queue); try { $tr->validate_import_data(); } catch (Exception $e) { throw new ImportException(null, 'Invalid importdata: ' . $e->getMessage()); } if (!array_key_exists('totalsize', $importdata)) { throw new ImportException(null, 'Invalid importdata: missing totalsize'); } if (!$user->quota_allowed($importdata['totalsize'])) { $e = new ImportException(null, 'Exceeded user quota'); $e->set_log_off(); throw $e; } $result = new StdClass(); if ($fetchnow && PluginImport::import_immediately_allowed()) { // either immediately spawn a curl request to go fetch the file $importer = PluginImport::create_importer($queue->id, $tr, $queue); $importer->prepare(); try { $importer->validate_transported_data($tr); } catch (Exception $e) { throw new ImportException(null, 'Invalid importdata: ' . $e->getMessage()); } $importer->process(); $importer->cleanup(); delete_records('import_queue', 'id', $queue->id); $result->status = true; $result->type = 'complete'; $returndata = $importer->get_return_data(); $result->querystring = '?'; foreach ($importer->get_return_data() as $k => $v) { $result->querystring .= $k . '=' . $v . '&'; } $importer->get('importertransport')->cleanup(); } else { // or set ready to 1 for the next cronjob to go fetch it. $result->status = set_field('import_queue', 'ready', 1, 'id', $queue->id); $result->type = 'queued'; } return $result; }
public function __construct($message, ImportRun $importRun, \Exception $previous = null) { parent::__construct($message . "\n" . print_r($importRun, true), 0, $previous); $this->importRun = $importRun; }
protected function init_db() { try { list($db_server, $db_user, $db_passwd, $db_persist, $db_prefix, $db_name) = $this->config->destination->dbConnectionData(); $this->db = new Database($db_server, $db_user, $db_passwd, $db_persist); //We want UTF8 only, let's set our mysql connetction to utf8 $this->db->query('SET NAMES \'utf8\''); } catch (Exception $e) { ImportException::exception_handler($e, $this->template); die; } if (strpos($db_prefix, '.') === false) { // @todo ??? if (is_numeric(substr($db_prefix, 0, 1))) { $this->config->to_prefix = $db_name . '.' . $db_prefix; } else { $this->config->to_prefix = '`' . $db_name . '`.' . $db_prefix; } } else { $this->config->to_prefix = $db_prefix; } $this->config->from_prefix = $this->config->source->getPrefix(); if (preg_match('~^`[^`]+`.\\d~', $this->config->from_prefix) != 0) { $this->config->from_prefix = strtr($this->config->from_prefix, array('`' => '')); } // SQL_BIG_SELECTS: If set to 0, MySQL aborts SELECT statements that are // likely to take a very long time to execute (that is, statements for // which the optimizer estimates that the number of examined rows exceeds // the value of max_join_size) // Source: // https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_sql_big_selects $this->db->query("SET @@SQL_BIG_SELECTS = 1"); $this->db->query("SET @@MAX_JOIN_SIZE = 18446744073709551615"); }