Merge branch 'master' of git.beeznest.com:minedu-chamilo

skala
Julio Montoya 12 years ago
commit d5e4eb909d
  1. 5
      console.php
  2. 10
      main/exercice/exercise.class.php
  3. 4
      main/exercice/fill_blanks.class.php
  4. 4
      main/exercice/freeanswer.class.php
  5. 4
      main/exercice/global_multiple_answer.class.php
  6. 4
      main/exercice/hotspot.class.php
  7. 4
      main/exercice/matching.class.php
  8. 4
      main/exercice/media_question.class.php
  9. 4
      main/exercice/multiple_answer.class.php
  10. 4
      main/exercice/multiple_answer_combination.class.php
  11. 4
      main/exercice/multiple_answer_true_false.class.php
  12. 4
      main/exercice/oral_expression.class.php
  13. 10
      main/exercice/question.class.php
  14. 4
      main/exercice/unique_answer.class.php
  15. 4
      main/exercice/unique_answer_no_option.class.php
  16. 14
      main/inc/lib/api.lib.php
  17. 1
      main/inc/lib/database.constants.inc.php
  18. 35
      src/ChamiloLMS/Command/Transaction/ImportToSystemCommand.php
  19. 56
      src/ChamiloLMS/Command/Transaction/MineduSendCommand.php
  20. 35
      src/ChamiloLMS/Command/Transaction/ProcessReceivedEnvelopesCommand.php
  21. 31
      src/ChamiloLMS/Command/Transaction/ReceiveCommand.php
  22. 105
      src/ChamiloLMS/Command/Transaction/SendCommand.php
  23. 4
      src/ChamiloLMS/Transaction/Plugin/AuthHttpsPostSend.php
  24. 45
      src/ChamiloLMS/Transaction/Plugin/MineduAuthHttpsPostSend.php
  25. 11
      src/ChamiloLMS/Transaction/TransactionLogController.php

@ -76,6 +76,11 @@ $cli->addCommands(
// Chamilo commands. // Chamilo commands.
new ChamiloLMS\Command\Template\AsseticDumpCommand(), new ChamiloLMS\Command\Template\AsseticDumpCommand(),
new ChamiloLMS\Command\Transaction\ImportToSystemCommand(),
new ChamiloLMS\Command\Transaction\ReceiveCommand(),
new ChamiloLMS\Command\Transaction\ProcessReceivedEnvelopesCommand(),
new ChamiloLMS\Command\Transaction\SendCommand(),
new ChamiloLMS\Command\Transaction\MineduSendCommand(),
new ChamiloLMS\Command\Translation\ExportLanguagesCommand(), new ChamiloLMS\Command\Translation\ExportLanguagesCommand(),
// Chash commands. // Chash commands.

@ -148,8 +148,8 @@ class Exercise
} }
$this->course_id = $course_info['real_id']; $this->course_id = $course_info['real_id'];
$this->course = $course_info; $this->course = $course_info;
$this->fastEdition = api_get_course_setting('allow_fast_exercise_edition') == 1 ? true : false; $this->fastEdition = api_get_course_setting('allow_fast_exercise_edition', $course_info['code']) == 1 ? true : false;
$this->emailAlert = api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ? true : false; $this->emailAlert = api_get_course_setting('email_alert_manager_on_new_quiz', $course_info['code']) == 1 ? true : false;
$this->hideQuestionTitle = 0; $this->hideQuestionTitle = 0;
} }
@ -5324,12 +5324,12 @@ class Exercise
* </code> * </code>
* @return array * @return array
*/ */
private function setMediaList($questionList) private function setMediaList($questionList, $course_id)
{ {
$mediaList= array(); $mediaList= array();
if (!empty($questionList)) { if (!empty($questionList)) {
foreach ($questionList as $questionId) { foreach ($questionList as $questionId) {
$objQuestionTmp = Question::read($questionId); $objQuestionTmp = Question::read($questionId, $course_id);
// If a media question exists // If a media question exists
if (isset($objQuestionTmp->parent_id) && $objQuestionTmp->parent_id != 0) { if (isset($objQuestionTmp->parent_id) && $objQuestionTmp->parent_id != 0) {
@ -5496,7 +5496,7 @@ class Exercise
} }
} }
$this->setMediaList($questionList); $this->setMediaList($questionList, $this->course_id);
$this->questionList = $this->transformQuestionListWithMedias($questionList, false); $this->questionList = $this->transformQuestionListWithMedias($questionList, false);
$this->questionListUncompressed = $this->transformQuestionListWithMedias($questionList, true); $this->questionListUncompressed = $this->transformQuestionListWithMedias($questionList, true);

@ -30,9 +30,9 @@ class FillBlanks extends Question
/** /**
* Constructor * Constructor
*/ */
public function FillBlanks() public function FillBlanks($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = FILL_IN_BLANKS; $this->type = FILL_IN_BLANKS;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -24,9 +24,9 @@ class FreeAnswer extends Question
/** /**
* Constructor * Constructor
*/ */
public function __construct() public function __construct($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = FREE_ANSWER; $this->type = FREE_ANSWER;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -10,9 +10,9 @@ class GlobalMultipleAnswer extends Question
/** /**
* *
*/ */
public function GlobalMultipleAnswer() public function GlobalMultipleAnswer($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = GLOBAL_MULTIPLE_ANSWER; $this->type = GLOBAL_MULTIPLE_ANSWER;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -24,8 +24,8 @@ class HotSpot extends Question {
static $typePicture = 'hotspot.gif'; static $typePicture = 'hotspot.gif';
static $explanationLangVar = 'HotSpot'; static $explanationLangVar = 'HotSpot';
function HotSpot() { function HotSpot($course_code = null) {
parent::question(); parent::question($course_code);
$this -> type = HOT_SPOT; $this -> type = HOT_SPOT;
} }

@ -25,9 +25,9 @@ class Matching extends Question
/** /**
* Constructor * Constructor
*/ */
function Matching() function Matching($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = MATCHING; $this->type = MATCHING;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -6,9 +6,9 @@ class MediaQuestion extends Question
static $typePicture = 'media-question.png'; static $typePicture = 'media-question.png';
static $explanationLangVar = 'MediaQuestion'; static $explanationLangVar = 'MediaQuestion';
public function __construct() public function __construct($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = MEDIA_QUESTION; $this->type = MEDIA_QUESTION;
} }

@ -26,9 +26,9 @@ class MultipleAnswer extends Question
/** /**
* Constructor * Constructor
*/ */
public function MultipleAnswer() public function MultipleAnswer($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = MULTIPLE_ANSWER; $this->type = MULTIPLE_ANSWER;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -25,9 +25,9 @@ class MultipleAnswerCombination extends Question
/** /**
* Constructor * Constructor
*/ */
public function MultipleAnswerCombination() public function MultipleAnswerCombination($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = MULTIPLE_ANSWER_COMBINATION; $this->type = MULTIPLE_ANSWER_COMBINATION;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -25,9 +25,9 @@ class MultipleAnswerTrueFalse extends Question
/** /**
* Constructor * Constructor
*/ */
public function MultipleAnswerTrueFalse() public function MultipleAnswerTrueFalse($course_code = null)
{ {
parent::question(); parent::question($course_code);
$this->type = MULTIPLE_ANSWER_TRUE_FALSE; $this->type = MULTIPLE_ANSWER_TRUE_FALSE;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
$this->options = array(1 => get_lang('True'), 2 => get_lang('False'), 3 => get_lang('DoubtScore')); $this->options = array(1 => get_lang('True'), 2 => get_lang('False'), 3 => get_lang('DoubtScore'));

@ -23,8 +23,8 @@ class OralExpression extends Question
/** /**
* Constructor * Constructor
*/ */
function OralExpression(){ function OralExpression($course_code = null){
parent::question(); parent::question($course_code);
$this -> type = ORAL_EXPRESSION; $this -> type = ORAL_EXPRESSION;
$this -> isContent = $this-> getIsContent(); $this -> isContent = $this-> getIsContent();
} }

@ -73,7 +73,7 @@ abstract class Question
* *
* @author - Olivier Brouckaert * @author - Olivier Brouckaert
*/ */
public function Question() public function Question($course_code = null)
{ {
$this->id = 0; $this->id = 0;
$this->question = ''; $this->question = '';
@ -86,7 +86,7 @@ abstract class Question
//with an special hotspot: final_overlap, final_missing, final_excess //with an special hotspot: final_overlap, final_missing, final_excess
$this->extra = ''; $this->extra = '';
$this->exerciseList = array(); $this->exerciseList = array();
$this->course = api_get_course_info(); $this->course = api_get_course_info($course_code);
$this->category_list = array(); $this->category_list = array();
$this->parent_id = 0; $this->parent_id = 0;
$this->editionMode = 'normal'; $this->editionMode = 'normal';
@ -165,7 +165,7 @@ abstract class Question
// if the question has been found // if the question has been found
if ($object = Database::fetch_object($result)) { if ($object = Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type); $objQuestion = Question::getInstance($object->type, null, $course_info['code']);
if (!empty($objQuestion)) { if (!empty($objQuestion)) {
$objQuestion->id = $id; $objQuestion->id = $id;
@ -1329,14 +1329,14 @@ abstract class Question
* @param \Exercise * @param \Exercise
* @return \Question an instance of a Question subclass (or of Questionc class by default) * @return \Question an instance of a Question subclass (or of Questionc class by default)
*/ */
public static function getInstance($type, Exercise $exercise = null) public static function getInstance($type, Exercise $exercise = null, $course_code = null)
{ {
if (!is_null($type)) { if (!is_null($type)) {
list($file_name, $class_name) = self::get_question_type($type); list($file_name, $class_name) = self::get_question_type($type);
if (!empty($file_name)) { if (!empty($file_name)) {
include_once $file_name; include_once $file_name;
if (class_exists($class_name)) { if (class_exists($class_name)) {
$obj = new $class_name(); $obj = new $class_name($course_code);
$obj->exercise = $exercise; $obj->exercise = $exercise;
return $obj; return $obj;
} else { } else {

@ -29,10 +29,10 @@ class UniqueAnswer extends Question
/** /**
* Constructor * Constructor
*/ */
public function UniqueAnswer() public function UniqueAnswer($course_code = null)
{ {
//this is highly important //this is highly important
parent::question(); parent::question($course_code);
$this->type = UNIQUE_ANSWER; $this->type = UNIQUE_ANSWER;
$this->isContent = $this->getIsContent(); $this->isContent = $this->getIsContent();
} }

@ -30,9 +30,9 @@ class UniqueAnswerNoOption extends Question
/** /**
* Constructor * Constructor
*/ */
function UniqueAnswerNoOption(){ function UniqueAnswerNoOption($course_code = null){
//this is highly important //this is highly important
parent::question(); parent::question($course_code);
$this -> type = UNIQUE_ANSWER_NO_OPTION; $this -> type = UNIQUE_ANSWER_NO_OPTION;
$this -> isContent = $this-> getIsContent(); $this -> isContent = $this-> getIsContent();
} }

@ -1128,6 +1128,10 @@ function api_is_self_registration_allowed() {
* @return integer the id of the current user, 0 if is empty * @return integer the id of the current user, 0 if is empty
*/ */
function api_get_user_id() { function api_get_user_id() {
if (PHP_SAPI == 'cli') {
// Do not try to call session on CLI.
return 0;
}
$userInfo = Session::read('_user'); $userInfo = Session::read('_user');
if ($userInfo && isset($userInfo['user_id'])) { if ($userInfo && isset($userInfo['user_id'])) {
return $userInfo['user_id']; return $userInfo['user_id'];
@ -2154,6 +2158,16 @@ function api_get_session_condition($session_id, $and = true, $with_base_content
* @author Bart Mollet * @author Bart Mollet
*/ */
function api_get_setting($variable, $key = null) { function api_get_setting($variable, $key = null) {
if (PHP_SAPI == 'cli') {
// Do not use session on CLI.
// @todo Support key.
$variable_data = api_get_settings_params_simple(array("variable = '?'" => $variable));
if (isset($variable_data['selected_value'])) {
return $variable_data['selected_value'];
}
return '';
}
$_setting = Session::read('_setting'); $_setting = Session::read('_setting');
if ($variable == 'header_extra_content') { if ($variable == 'header_extra_content') {
$filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; $filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';

@ -347,6 +347,7 @@ define('TABLE_GRADE_MODEL', 'grade_model');
define('TABLE_GRADE_MODEL_COMPONENTS', 'grade_components'); define('TABLE_GRADE_MODEL_COMPONENTS', 'grade_components');
// Transaction related tables // Transaction related tables
define('TABLE_BRANCH_REL_SESSION', 'branch_rel_session');
define('TABLE_BRANCH_SYNC', 'branch_sync'); define('TABLE_BRANCH_SYNC', 'branch_sync');
define('TABLE_BRANCH_TRANSACTION', 'branch_transaction'); define('TABLE_BRANCH_TRANSACTION', 'branch_transaction');
define('TABLE_BRANCH_TRANSACTION_STATUS', 'branch_transaction_status'); define('TABLE_BRANCH_TRANSACTION_STATUS', 'branch_transaction_status');

@ -0,0 +1,35 @@
<?php
namespace ChamiloLMS\Command\Transaction;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ChamiloLMS\Transaction\TransactionLogController;
class ImportToSystemCommand extends Command
{
protected function configure()
{
$this
->setName('tx:import-to-system')
->setDescription('Imports transactions on the transaction table to the local system.')
->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'The maximum number of transactions to import into the system in this operation.', 10);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$tc = new TransactionLogController();
$limit = (int) $input->getOption('limit');
if ($limit <= 0) {
$limit = 10;
}
$imported_ids = $tc->importPendingToSystem($limit);
$output->writeln(sprintf('Imported correctly (%d) transactions to the system.', count($imported_ids['success'])));
if (!empty($imported_ids['fail'])) {
$output->writeln(sprintf('The transactions identified by the following ids failed to be imported: (%s)', implode(', ', $imported_ids['fail'])));
return 1;
}
}
}

@ -0,0 +1,56 @@
<?php
namespace ChamiloLMS\Command\Transaction;
use Database;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
/**
* A customization of tx:send for specific case.
*
* Assumtions:
* - branch_rel_session table only contains the local branch entries.
* - branch_rel_session.display_order represents a "turn".
*/
class MineduSendCommand extends Command
{
protected function configure()
{
$this
->setName('minedu:send')
->setDescription('Sends data using tx:send, using custom minedu logic to convert turn numbers into a course/session pair.')
->addArgument('turn', InputArgument::REQUIRED, 'The turn to be used.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// This is just wrong, but was requested. Used to pass a session_id to
// be used on the MineduAuthHttpsPostSend plugin.
global $session_id;
$turn = $input->getArgument('turn');
$branch_rel_session_table = Database::get_main_table(TABLE_BRANCH_REL_SESSION);
$results = Database::select('session_id', $branch_rel_session_table, array('where'=> array('display_order = ?' => array($turn))));
if (empty($results)) {
$output->writeln(sprintf('Failed to retrive a session id for the given turn "%s".', $turn));
return 100;
}
$row = array_shift($results);
$session_id = $row['session_id'];
$command = $this->getApplication()->find('tx:send');
$arguments = array(
'command' => 'tx:send',
'--session' => $session_id,
);
$input = new ArrayInput($arguments);
$return_code = $command->run($input, $output);
if ($return_code !== 0) {
$output->writeln('Failed trying to send the turn information.');
return $return_code;
}
}
}

@ -0,0 +1,35 @@
<?php
namespace ChamiloLMS\Command\Transaction;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ChamiloLMS\Transaction\TransactionLogController;
class ProcessReceivedEnvelopesCommand extends Command
{
protected function configure()
{
$this
->setName('tx:process-received-envelopes')
->setDescription('Process already received envelopes to extract its transactions to the transactions table.')
->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'The maximum number of received envelopes to process in this operation.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$tc = new TransactionLogController();
$limit = (int) $input->getOption('limit');
if ($limit <= 0) {
$limit = 10;
}
$imported_transaction_ids_by_envelope = $tc->importPendingEnvelopes($limit);
$total_transactions = 0;
foreach ($imported_transaction_ids_by_envelope as $envelope_id => $imported_transaction_ids) {
$total_transactions += count($imported_transaction_ids);
}
$output->writeln(sprintf('Imported correctly (%d) transactions from (%d) envelopes to the transactions table.', $total_transactions, count($imported_transaction_ids_by_envelope)));
}
}

@ -0,0 +1,31 @@
<?php
namespace ChamiloLMS\Command\Transaction;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ChamiloLMS\Transaction\TransactionLogController;
class ReceiveCommand extends Command
{
protected function configure()
{
$this
->setName('tx:receive')
->setDescription('Runs local branch associated receive plugin processing envelope reception.')
->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'The maximum number of envelopes to receive in this operation.', 1);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$tc = new TransactionLogController();
$limit = (int) $input->getOption('limit');
if ($limit <= 0) {
$limit = 1;
}
$envelopes = $tc->receiveEnvelopeData($limit);
$output->writeln(sprintf('Correctly received (%d) envelopes now added to the queue.', count($envelopes)));
}
}

@ -0,0 +1,105 @@
<?php
namespace ChamiloLMS\Command\Transaction;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use ChamiloLMS\Transaction\Envelope;
use ChamiloLMS\Transaction\TransactionLogController;
use ChamiloLMS\Transaction\TransactionLog;
/**
* Selects a subset of transactions, wraps and send them.
*
* It will use local branch settings.
*/
class SendCommand extends Command
{
protected $local_branch = null;
public function __construct(string $name = null)
{
parent::__construct($name);
// @todo Is there a clean way/no-global to access app from here?
global $app;
$this->local_branch = $app['orm.em']->getRepository('Entity\BranchSync')->getLocalBranch();
}
/**
* @todo Let accept multiple values on options. Notice Database::select()
* does not allow multiple values.
*/
protected function configure()
{
$this
->setName('tx:send')
->setDescription('Selects a subset of transactions, wraps and send them using local branch configuration.')
->addOption('course', null, InputOption::VALUE_OPTIONAL, 'A course ID to select transactions.', '')
->addOption('session', null, InputOption::VALUE_OPTIONAL, 'A session ID to select transactions.', '');
}
/**
* Convert input options into TransactionLogController::load() conditions.
*
* @todo Validate arguments?
*/
protected function getSelectConditions(InputInterface $input)
{
$conditions = array(
'branch_id' => $this->local_branch->getId(),
'status_id' => TransactionLog::STATUS_LOCAL,
);
// Course.
$course_string = $input->getOption('course');
if (strlen($course_string) > 0) {
$conditions['c_id'] = $course_string;
}
// Session.
$session_string = $input->getOption('session');
if (strlen($session_string) > 0) {
$conditions['session_id'] = $session_string;
}
return $conditions;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$tc = new TransactionLogController();
$transactions = $tc->load($this->getSelectConditions($input));
if (empty($transactions)) {
$output->writeln('No transactions to be exported');
return 1;
}
// Export.
$export_result = $tc->exportTransactions($transactions);
if (!empty($export_result['fail'])) {
$fail_data = print_r($export_result['fail'], 1);
$output->writeln('Failed exporting some transactions:');
$output->writeln("$fail_data");
return 2;
}
// Create an evelope and wrap it.
$wrapper = TransactionLogController::createPlugin('wrapper', $this->local_branch->getPluginEnvelope(), $this->local_branch->getPluginData('wrapper'));
$envelope_data = array('transactions' => $transactions, 'origin_branch_id' => $this->local_branch->getId());
$envelope = new Envelope($wrapper, $envelope_data);
try {
$envelope->wrap();
}
catch (Exception $e) {
$output->writeln(sprintf('Failed wrapping the envelope: %s.', $e->getMessage()));
return 3;
}
// Finally send it.
$success = $tc->sendEnvelope($envelope);
if ($success !== TRUE) {
$output->writeln('There was a problem while sending the envelope.');
return 4;
}
$output->writeln('Envelope sent!');
}
}

@ -71,7 +71,7 @@ class AuthHttpsPostSend implements SendPluginInterface
throw new SendException('auth_https_post: Cannot retrieve blob from envelope.'); throw new SendException('auth_https_post: Cannot retrieve blob from envelope.');
} }
if (!$blob_file = $this->getTemporaryFile('blob_file')) { if (!$blob_file = $this->getTemporaryFileToSend('blob_file', $envelope)) {
throw new SendException(sprintf('auth_https_post: Unable to create correctly the temporary blob file on "%s".', $blob_file)); throw new SendException(sprintf('auth_https_post: Unable to create correctly the temporary blob file on "%s".', $blob_file));
} }
if (file_put_contents($blob_file, $blob) === false) { if (file_put_contents($blob_file, $blob) === false) {
@ -112,7 +112,7 @@ class AuthHttpsPostSend implements SendPluginInterface
* @see SslSignedJsonWrapper. * @see SslSignedJsonWrapper.
* @todo Unify on a common base plugin parent. * @todo Unify on a common base plugin parent.
*/ */
protected function getTemporaryFile($name) { protected function getTemporaryFileToSend($name, Envelope $envelope) {
static $tmp_directory; static $tmp_directory;
if (!isset($tmp_directory)) { if (!isset($tmp_directory)) {
$tmp_directory = api_get_path(SYS_DATA_PATH) . 'transaction_tmp_files'; $tmp_directory = api_get_path(SYS_DATA_PATH) . 'transaction_tmp_files';

@ -0,0 +1,45 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Transaction\Plugin;
use ChamiloLMS\Transaction\Envelope;
/**
* Customization to have an specific file name.
*/
class MineduAuthHttpsPostSend extends AuthHttpsPostSend
{
/**
* Base name for files to send for minedu.
*/
const BASE_NAME='PE_0265';
/**
* {@inheritdoc}
*/
public static function getMachineName()
{
return 'minedu_auth_https_post';
}
/**
* A custom name for the teporary filename to send via curl.
* Retrieves a temporary filename.
*/
protected function getTemporaryFileToSend($name, Envelope $envelope) {
// @fixme This is just wrong but it was requested. An Envelope nor any
// place from here really knows which session_id to use because an
// Envelope just contains a list of transactions, it does not matter if
// they are part of one session or multiple ones.
global $session_id;
if ($name != 'blob_file') {
return parent::getTemporaryFileToSend($name, $envelope);
}
// At blob_file request.
$stamp = str_replace(array(' ', ':', '-'), '', api_get_datetime());
$filename = sprintf('%s_%05d_%05d_%s_', self::BASE_NAME, $envelope->getOriginBranchId(), $session_id, $stamp);
return parent::getTemporaryFileToSend($filename, $envelope);
}
}

@ -166,6 +166,10 @@ class TransactionLogController
* *
* @param integer $limit * @param integer $limit
* The maximum allowed envelopes to process. 0 means unlimited. * The maximum allowed envelopes to process. 0 means unlimited.
*
* @return array
* An array keyed by received envelope id containing an array transaction
* ids added based on that received envelope.
*/ */
public static function importPendingEnvelopes($limit = 0) { public static function importPendingEnvelopes($limit = 0) {
$table = Database::get_main_table(TABLE_RECEIVED_ENVELOPES); $table = Database::get_main_table(TABLE_RECEIVED_ENVELOPES);
@ -177,6 +181,7 @@ class TransactionLogController
else { else {
$sql = sprintf('SELECT * FROM %s WHERE status = %d LIMIT %d', $table, Envelope::RECEIVED_TO_BE_IMPORTED, $limit); $sql = sprintf('SELECT * FROM %s WHERE status = %d LIMIT %d', $table, Envelope::RECEIVED_TO_BE_IMPORTED, $limit);
} }
$added_transaction_ids_per_envelope = array();
$result = Database::query($sql); $result = Database::query($sql);
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
try { try {
@ -187,7 +192,8 @@ class TransactionLogController
$envelope = new Envelope($wrapper_plugin, $envelope_data); $envelope = new Envelope($wrapper_plugin, $envelope_data);
$envelope->unwrap(); $envelope->unwrap();
$transactions = $envelope->getTransactions(); $transactions = $envelope->getTransactions();
$this->importToLog($transactions); $added_transaction_ids = $this->importToLog($transactions);
$added_transaction_ids_per_envelope[$row['id']] = $added_transaction_ids;
Database::update($table, array('status' => Envelope::RECEIVED_IMPORTED), array('id = ?' => $row['id'])); Database::update($table, array('status' => Envelope::RECEIVED_IMPORTED), array('id = ?' => $row['id']));
} }
catch (Exception $exception) { catch (Exception $exception) {
@ -196,6 +202,8 @@ class TransactionLogController
continue; continue;
} }
} }
return $added_transaction_ids_per_envelope;
} }
@ -420,6 +428,7 @@ class TransactionLogController
'send' => array( 'send' => array(
'none' => 'NoneSendPlugin', 'none' => 'NoneSendPlugin',
'auth_https_post' => 'AuthHttpsPostSend', 'auth_https_post' => 'AuthHttpsPostSend',
'minedu_auth_https_post' => 'MineduAuthHttpsPostSend',
), ),
'receive' => array( 'receive' => array(
'none' => 'NoneReceivePlugin', 'none' => 'NoneReceivePlugin',

Loading…
Cancel
Save