skala
Laurent Opprecht 13 years ago
commit cdd58d19b9
  1. 1
      main/auth/shibboleth/login.php
  2. 8
      main/auth/shibboleth/test/shibboleth_test_helper.class.php
  3. 24
      main/inc/lib/add_course.lib.inc.php
  4. 1
      main/inc/lib/autoload.class.php
  5. 18
      main/inc/lib/database.lib.php
  6. 223
      main/inc/lib/log.class.php
  7. 2
      main/inc/lib/main_api.lib.php
  8. 36
      main/inc/lib/symfony/Monolog/Formatter/FormatterInterface.php
  9. 40
      main/inc/lib/symfony/Monolog/Formatter/JsonFormatter.php
  10. 105
      main/inc/lib/symfony/Monolog/Formatter/LineFormatter.php
  11. 87
      main/inc/lib/symfony/Monolog/Formatter/WildfireFormatter.php
  12. 169
      main/inc/lib/symfony/Monolog/Handler/AbstractHandler.php
  13. 70
      main/inc/lib/symfony/Monolog/Handler/AbstractProcessingHandler.php
  14. 67
      main/inc/lib/symfony/Monolog/Handler/BufferHandler.php
  15. 95
      main/inc/lib/symfony/Monolog/Handler/FingersCrossedHandler.php
  16. 159
      main/inc/lib/symfony/Monolog/Handler/FirePHPHandler.php
  17. 74
      main/inc/lib/symfony/Monolog/Handler/GroupHandler.php
  18. 77
      main/inc/lib/symfony/Monolog/Handler/HandlerInterface.php
  19. 54
      main/inc/lib/symfony/Monolog/Handler/MailHandler.php
  20. 49
      main/inc/lib/symfony/Monolog/Handler/NativeMailerHandler.php
  21. 37
      main/inc/lib/symfony/Monolog/Handler/NullHandler.php
  22. 109
      main/inc/lib/symfony/Monolog/Handler/RotatingFileHandler.php
  23. 72
      main/inc/lib/symfony/Monolog/Handler/StreamHandler.php
  24. 55
      main/inc/lib/symfony/Monolog/Handler/SwiftMailerHandler.php
  25. 109
      main/inc/lib/symfony/Monolog/Handler/SyslogHandler.php
  26. 120
      main/inc/lib/symfony/Monolog/Handler/TestHandler.php
  27. 394
      main/inc/lib/symfony/Monolog/Logger.php
  28. 58
      main/inc/lib/symfony/Monolog/Processor/IntrospectionProcessor.php
  29. 40
      main/inc/lib/symfony/Monolog/Processor/MemoryPeakUsageProcessor.php
  30. 50
      main/inc/lib/symfony/Monolog/Processor/MemoryProcessor.php
  31. 40
      main/inc/lib/symfony/Monolog/Processor/MemoryUsageProcessor.php
  32. 60
      main/inc/lib/symfony/Monolog/Processor/WebProcessor.php
  33. 45
      main/install/i_database.class.php
  34. 37
      main/install/index.php
  35. 16
      main/install/install.class.php
  36. 4
      main/install/install.lib.php
  37. 13
      main/install/migrate-db-1.8.8-1.9.0-pre.sql
  38. 116
      main/install/update-configuration.inc.php
  39. 998
      main/install/update-db-1.6.x-1.8.0.inc.php
  40. 367
      main/install/update-db-1.8.0-1.8.2.inc.php
  41. 2
      main/install/update-db-1.8.2-1.8.3.inc.php
  42. 2
      main/install/update-db-1.8.3-1.8.4.inc.php
  43. 2
      main/install/update-db-1.8.4-1.8.5.inc.php
  44. 124
      main/install/update-db-1.8.5-1.8.6.inc.php
  45. 74
      main/install/update-db-1.8.6-1.8.6.1.inc.php
  46. 110
      main/install/update-db-1.8.6.1-1.8.6.2.inc.php
  47. 458
      main/install/update-db-1.8.6.2-1.8.7.inc.php
  48. 152
      main/install/update-db-1.8.7-1.8.8.inc.php
  49. 116
      main/install/update-db-1.8.8-1.9.0.inc.php
  50. 86
      main/install/update-db-scorm-1.6.x-1.8.0.inc.php
  51. 246
      main/install/update-files-1.6.x-1.8.0.inc.php
  52. 2
      main/install/update-files-1.8.3-1.8.4.inc.php
  53. 2
      main/install/update-files-1.8.4-1.8.5.inc.php
  54. 181
      main/install/update-files-1.8.5-1.8.6.inc.php
  55. 2
      main/install/update-files-1.8.6-1.8.6.1.inc.php
  56. 126
      main/install/update-files-1.8.6.1-1.8.6.2.inc.php
  57. 2
      main/install/update-files-1.8.6.2-1.8.7.inc.php
  58. 2
      main/install/update-files-1.8.7-1.8.8.inc.php
  59. 2
      main/install/update-files-1.8.8-1.9.0.inc.php

@ -28,5 +28,6 @@ include_once(dirname(__FILE__) . '/init.php');
//ShibbolethTest::helper()->setup_new_staff();
//ShibbolethTest::helper()->setup_new_teacher();
//ShibbolethTest::helper()->setup_new_student();
//ShibbolethTest::helper()->setup_new_minimal_data();
ShibbolethController::instance()->login();

@ -109,4 +109,12 @@ class ShibbolethTestHelper
$_SERVER['persistent-id'] = 'idp!viewer!' . md5($id);
}
public function setup_new_minimal_data()
{
$id = uniqid();
$_SERVER['Shib-SwissEP-UniqueID'] = 'usr_' . $id;
$_SERVER['Shib-InetOrgPerson-givenName'] = 'John';
$_SERVER['Shib-Person-surname'] = 'Doe' . $id;
}
}

@ -599,7 +599,8 @@ function create_course_tables($course_db_name = null) {
$add_to_all_tables
thread_id int default NULL,
user_id int default NULL,
post_id int default NULL
post_id int default NULL,
PRIMARY KEY ( c_id, thread_id, user_id, post_id )
)" . $charset_clause;
Database::query($sql);
@ -624,7 +625,8 @@ function create_course_tables($course_db_name = null) {
thread_id int,
post_id int,
KEY user_id (user_id),
KEY forum_id (forum_id)
KEY forum_id (forum_id),
PRIMARY KEY ( c_id, user_id, forum_id, thread_id, post_id ),
)" . $charset_clause;
Database::query($sql);
@ -1035,7 +1037,8 @@ function create_course_tables($course_db_name = null) {
startdate_assig datetime NOT NULL default '0000-00-00 00:00:00',
enddate_assig datetime NOT NULL default '0000-00-00 00:00:00',
delayedsubmit int NOT NULL default 0,
KEY page_id (page_id)
KEY page_id (page_id),
PRIMARY KEY ( c_id, page_id )
)" . $charset_clause;
Database::query($sql);
@ -1058,7 +1061,8 @@ function create_course_tables($course_db_name = null) {
type text NOT NULL,
group_id int DEFAULT NULL,
session_id smallint default 0,
KEY (c_id, id)
KEY (c_id, id),
PRIMARY KEY ( c_id, id, user_id )
)" . $charset_clause;
Database::query($sql);
@ -1091,7 +1095,8 @@ function create_course_tables($course_db_name = null) {
user_id int unsigned NOT NULL default '0',
last_connection datetime NOT NULL default '0000-00-00 00:00:00',
session_id INT NOT NULL default 0,
to_group_id INT NOT NULL default 0
to_group_id INT NOT NULL default 0,
PRIMARY KEY ( `c_id`, `user_id`, `last_connection` )
)" . $charset_clause;
Database::query($sql);
@ -1652,7 +1657,8 @@ function create_course_tables($course_db_name = null) {
$add_to_all_tables
role_id int NOT NULL default 0,
scope varchar( 20 ) NOT NULL default 'course',
group_id int NOT NULL default 0
group_id int NOT NULL default 0,
PRIMARY KEY (group_id )
)" . $charset_clause;
if (!Database::query($sql)) {
@ -1665,7 +1671,8 @@ function create_course_tables($course_db_name = null) {
role_id int NOT NULL default 0,
tool varchar( 250 ) NOT NULL default '',
action varchar( 50 ) NOT NULL default '',
default_perm tinyint NOT NULL default 0
default_perm tinyint NOT NULL default 0,
PRIMARY KEY ( c_id, role_id, tool, action )
)" . $charset_clause;
if (!Database::query($sql)) {
@ -1677,7 +1684,8 @@ function create_course_tables($course_db_name = null) {
$add_to_all_tables
role_id int NOT NULL default 0,
scope varchar( 20 ) NOT NULL default 'course',
user_id int NOT NULL default 0
user_id int NOT NULL default 0,
PRIMARY KEY ( c_id, role_id, user_id )
)" . $charset_clause;
if (!Database::query($sql)) {

@ -221,6 +221,7 @@ class Autoload
$result['LinkCategory'] = '/main/coursecopy/classes/LinkCategory.class.php';
$result['LinkFactory'] = '/main/gradebook/lib/be/linkfactory.class.php';
$result['LinkForm'] = '/main/gradebook/lib/fe/linkform.class.php';
$result['Log'] = '/main/inc/lib/log.class.php';
$result['Login'] = '/main/inc/lib/login.lib.php';
$result['LoginRedirection'] = '/main/inc/lib/login_redirection.class.php';
$result['Matching'] = '/main/exercice/matching.class.php';

@ -397,9 +397,17 @@ class Database {
if (!isset($parameters['client_flags'])) {
$parameters['client_flags'] = 0;
}
return $parameters['persistent']
? mysql_pconnect($parameters['server'], $parameters['username'], $parameters['password'], $parameters['client_flags'])
: mysql_connect($parameters['server'], $parameters['username'], $parameters['password'], $parameters['new_link'], $parameters['client_flags']);
$persistent = isset($parameters['persistent']) ? $parameters['persistent'] : null;
$server = isset($parameters['server']) ? $parameters['server'] : null;
$username = isset($parameters['username']) ? $parameters['username'] : null;
$password = isset($parameters['password']) ? $parameters['password'] : null;
$client_flag = isset($parameters['client_flags']) ? $parameters['client_flags'] : null;
$new_link = isset($parameters['new_link']) ? $parameters['new_link'] : null;
$client_flags = isset($parameters['client_flags']) ? $parameters['client_flags'] : null;
return $persistent
? mysql_pconnect($server, $username, $password, $client_flags)
: mysql_connect($server, $username, $password, $new_link, $client_flags);
}
/**
@ -761,9 +769,9 @@ class Database {
if (empty($line) && $line !== false) {
$line = $caller['line'];
}
$type = $owner['type'];
$type = isset($owner['type']) ? $owner['type'] : null;
$function = $owner['function'];
$class = $owner['class'];
$class = isset($owner['class']) ? $owner['class'] : null;
$server_type = api_get_setting('server_type');
if (!empty($line) && !empty($server_type) && $server_type != 'production') {
$info = '<pre>' .

@ -0,0 +1,223 @@
<?php
use Monolog\Logger;
/**
* Since static constructors do not exist in php the line below serves as a
* substitute.
*
* Log is used by install which do not use autoload at the moment. If it becomes
* the case then the line below may/should be moved to the main autoloading
* function.
*/
Log::register_autoload();
/**
* Provides access to the main log - i.e. stderr - and allows to register events.
* It is a facade to the monolog library:
*
* Log::error('message');
* Log::warning('message');
* ...
*
*
* Note:
* This class uses a static approach which has the benefit of being simpler but do
* no allow as much freedom as using an object approche. Another approach could be
*
* Chamilo::log()->error('message');
* Chamilo::log()->warning('message');
*
* To somewhat alleviate this issue the user can register a different logger if hew
* wants.
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class Log
{
public static function register_autoload()
{
static $has_run = false;
if ($has_run) {
return true;
}
$directory = api_get_path(LIBRARY_PATH) . 'symfony';
if (!class_exists('Doctrine\Common\ClassLoader', false)) {
require_once $directory . '/Doctrine/Common/ClassLoader.php';
}
$loader = new Doctrine\Common\ClassLoader('Monolog', $directory);
$loader->register();
$has_run = true;
}
/**
*
* @return \Monolog\Logger
*/
public static function default_logger()
{
$name = 'chamilo';
$result = new Logger($name);
$handler = new Monolog\Handler\StreamHandler('php://stderr');
$handler->setFormatter(new Monolog\Formatter\LineFormatter('[%datetime%] [%level_name%] [%channel%] %message%' . PHP_EOL, 'Y-m-d H:i:s')); //%context% %extra%
$result->pushHandler($handler);
return $result;
}
private static $logger = null;
/**
*
* @return \Monolog\Logger
*/
public static function logger()
{
if (empty(self::$logger)) {
self::$logger = self::default_logger();
}
return self::$logger;
}
public static function set_logger($value)
{
self::$logger = $value;
}
/**
* Returns the
* @param type $index
* @return type
*/
public static function frame($index)
{
$result = debug_backtrace();
return isset($result[$index]) ? $result[$index] : array();
}
public static function write($level, $message, $context = array())
{
/*
* Note that the same could be done with a monolog processor.
*/
if (!isset($context['file'])) {
$trace = debug_backtrace();
array_shift($trace);
$trace = reset($trace);
$context['file'] = $trace['file'];
$context['line'] = $trace['line'];
}
$file = $context['file'];
$root = realpath(api_get_path(SYS_PATH));
$file = str_replace($root, '', $file);
$file = trim($file, DIRECTORY_SEPARATOR);
$line = $context['line'];
$line = str_pad($line, 4, ' ', STR_PAD_LEFT);
$message = "[$file:$line] " . $message;
self::logger()->addRecord($level, $message, $context);
}
/**
* Adds a log record at the DEBUG level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function debug($message, array $context = array())
{
return self::write(Logger::DEBUG, $message, $context);
}
/**
* Adds a log record at the INFO level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function info($message, array $context = array())
{
return self::write(Logger::INFO, self::message($message), $context);
}
/**
* Adds a log record at the INFO level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function notice($message, array $context = array())
{
return self::write(Logger::INFO, $message, $context);
}
/**
* Adds a log record at the WARNING level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function warning($message, array $context = array())
{
return self::write(Logger::WARNING, $message, $context);
}
/**
* Adds a log record at the ERROR level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function error($message, array $context = array())
{
return self::write(Logger::ERROR, $message, $context);
}
/**
* Adds a log record at the CRITICAL level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function crit($message, array $context = array())
{
return self::write(Logger::CRITICAL, $message, $context);
}
/**
* Adds a log record at the ALERT level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public static function alert($message, array $context = array())
{
return self::write(Logger::ALERT, $message, $context);
}
}

@ -1062,7 +1062,7 @@ function api_get_user_info_from_username($username = '') {
* Returns the current course code (string)
*/
function api_get_course_id() {
return $GLOBALS['_cid'];
return isset($GLOBALS['_cid']) ? $GLOBALS['_cid'] : null;
}
/**

@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Formatter;
/**
* Interface for formatters
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface FormatterInterface
{
/**
* Formats a log record.
*
* @param array $record A record to format
* @return mixed The formatted record
*/
function format(array $record);
/**
* Formats a set of log records.
*
* @param array $records A set of records to format
* @return mixed The formatted set of records
*/
function formatBatch(array $records);
}

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Formatter;
use Monolog\Logger;
/**
* Encodes whatever record data is passed to it as json
*
* This can be useful to log to databases or remote APIs
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class JsonFormatter implements FormatterInterface
{
/**
* {@inheritdoc}
*/
public function format(array $record)
{
return json_encode($record);
}
/**
* {@inheritdoc}
*/
public function formatBatch(array $records)
{
return json_encode($records);
}
}

@ -0,0 +1,105 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Formatter;
use Monolog\Logger;
/**
* Formats incoming records into a one-line string
*
* This is especially useful for logging to files
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Christophe Coevoet <stof@notk.org>
*/
class LineFormatter implements FormatterInterface
{
const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
const SIMPLE_DATE = "Y-m-d H:i:s";
protected $format;
protected $dateFormat;
/**
* @param string $format The format of the message
* @param string $dateFormat The format of the timestamp: one supported by DateTime::format
*/
public function __construct($format = null, $dateFormat = null)
{
$this->format = $format ?: static::SIMPLE_FORMAT;
$this->dateFormat = $dateFormat ?: static::SIMPLE_DATE;
}
/**
* {@inheritdoc}
*/
public function format(array $record)
{
$vars = $record;
$vars['datetime'] = $vars['datetime']->format($this->dateFormat);
$output = $this->format;
foreach ($vars['extra'] as $var => $val) {
if (false !== strpos($output, '%extra.'.$var.'%')) {
$output = str_replace('%extra.'.$var.'%', $this->convertToString($val), $output);
unset($vars['extra'][$var]);
}
}
foreach ($vars as $var => $val) {
$output = str_replace('%'.$var.'%', $this->convertToString($val), $output);
}
return $output;
}
public function formatBatch(array $records)
{
$message = '';
foreach ($records as $record) {
$message .= $this->format($record);
}
return $message;
}
protected function convertToString($data)
{
if (null === $data || is_scalar($data)) {
return (string) $data;
}
return stripslashes(json_encode($this->normalize($data)));
}
protected function normalize($data)
{
if (null === $data || is_scalar($data)) {
return $data;
}
if (is_array($data) || $data instanceof \Traversable) {
$normalized = array();
foreach ($data as $key => $value) {
$normalized[$key] = $this->normalize($value);
}
return $normalized;
}
if (is_resource($data)) {
return '[resource]';
}
return sprintf("[object] (%s: %s)", get_class($data), json_encode($data));
}
}

@ -0,0 +1,87 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Formatter;
use Monolog\Logger;
/**
* Serializes a log message according to Wildfire's header requirements
*
* @author Eric Clemmons (@ericclemmons) <eric@uxdriven.com>
* @author Christophe Coevoet <stof@notk.org>
* @author Kirill chEbba Chebunin <iam@chebba.org>
*/
class WildfireFormatter implements FormatterInterface
{
/**
* Translates Monolog log levels to Wildfire levels.
*/
private $logLevels = array(
Logger::DEBUG => 'LOG',
Logger::INFO => 'INFO',
Logger::WARNING => 'WARN',
Logger::ERROR => 'ERROR',
Logger::CRITICAL => 'ERROR',
Logger::ALERT => 'ERROR',
);
/**
* {@inheritdoc}
*/
public function format(array $record)
{
// Retrieve the line and file if set and remove them from the formatted extra
$file = $line = '';
if (isset($record['extra']['file'])) {
$file = $record['extra']['file'];
unset($record['extra']['file']);
}
if (isset($record['extra']['line'])) {
$line = $record['extra']['line'];
unset($record['extra']['line']);
}
$message = array('message' => $record['message']);
if ($record['context']) {
$message['context'] = $record['context'];
}
if ($record['extra']) {
$message['extra'] = $record['extra'];
}
if (count($message) === 1) {
$message = reset($message);
}
// Create JSON object describing the appearance of the message in the console
$json = json_encode(array(
array(
'Type' => $this->logLevels[$record['level']],
'File' => $file,
'Line' => $line,
'Label' => $record['channel'],
),
$message,
));
// The message itself is a serialization of the above JSON object + it's length
return sprintf(
'%s|%s|',
strlen($json),
$json
);
}
public function formatBatch(array $records)
{
throw new \BadMethodCallException('Batch formatting does not make sense for the WildfireFormatter');
}
}

@ -0,0 +1,169 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/**
* Base Handler class providing the Handler structure
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
abstract class AbstractHandler implements HandlerInterface
{
protected $level = Logger::DEBUG;
protected $bubble = false;
/**
* @var FormatterInterface
*/
protected $formatter;
protected $processors = array();
/**
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($level = Logger::DEBUG, $bubble = true)
{
$this->level = $level;
$this->bubble = $bubble;
}
/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
return $record['level'] >= $this->level;
}
/**
* {@inheritdoc}
*/
public function handleBatch(array $records)
{
foreach ($records as $record) {
$this->handle($record);
}
}
/**
* Closes the handler.
*
* This will be called automatically when the object is destroyed
*/
public function close()
{
}
/**
* {@inheritdoc}
*/
public function pushProcessor($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
}
array_unshift($this->processors, $callback);
}
/**
* {@inheritdoc}
*/
public function popProcessor()
{
if (!$this->processors) {
throw new \LogicException('You tried to pop from an empty processor stack.');
}
return array_shift($this->processors);
}
/**
* {@inheritdoc}
*/
public function setFormatter(FormatterInterface $formatter)
{
$this->formatter = $formatter;
}
/**
* {@inheritdoc}
*/
public function getFormatter()
{
if (!$this->formatter) {
$this->formatter = $this->getDefaultFormatter();
}
return $this->formatter;
}
/**
* Sets minimum logging level at which this handler will be triggered.
*
* @param integer $level
*/
public function setLevel($level)
{
$this->level = $level;
}
/**
* Gets minimum logging level at which this handler will be triggered.
*
* @return integer
*/
public function getLevel()
{
return $this->level;
}
/**
* Sets the bubbling behavior.
*
* @param Boolean $bubble True means that bubbling is not permitted.
* False means that this handler allows bubbling.
*/
public function setBubble($bubble)
{
$this->bubble = $bubble;
}
/**
* Gets the bubbling behavior.
*
* @return Boolean True means that bubbling is not permitted.
* False means that this handler allows bubbling.
*/
public function getBubble()
{
return $this->bubble;
}
public function __destruct()
{
$this->close();
}
/**
* Gets the default formatter.
*
* @return FormatterInterface
*/
protected function getDefaultFormatter()
{
return new LineFormatter();
}
}

@ -0,0 +1,70 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/**
* Base Handler class providing the Handler structure
*
* Classes extending it should (in most cases) only implement write($record)
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Christophe Coevoet <stof@notk.org>
*/
abstract class AbstractProcessingHandler extends AbstractHandler
{
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
if ($record['level'] < $this->level) {
return false;
}
$record = $this->processRecord($record);
$record['formatted'] = $this->getFormatter()->format($record);
$this->write($record);
return false === $this->bubble;
}
/**
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @return void
*/
abstract protected function write(array $record);
/**
* Processes a record.
*
* @param array $record
* @return array
*/
protected function processRecord(array $record)
{
if ($this->processors) {
foreach ($this->processors as $processor) {
$record = call_user_func($processor, $record);
}
}
return $record;
}
}

@ -0,0 +1,67 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* Buffers all records until closing the handler and then pass them as batch.
*
* This is useful for a MailHandler to send only one mail per request instead of
* sending one per log message.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class BufferHandler extends AbstractHandler
{
protected $handler;
protected $bufferSize;
protected $buffer = array();
/**
* @param HandlerInterface $handler Handler.
* @param integer $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(HandlerInterface $handler, $bufferSize = 0, $level = Logger::DEBUG, $bubble = true)
{
parent::__construct($level, $bubble);
$this->handler = $handler;
$this->bufferSize = $bufferSize;
}
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
if ($record['level'] < $this->level) {
return false;
}
$this->buffer[] = $record;
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
array_shift($this->buffer);
}
return false === $this->bubble;
}
/**
* {@inheritdoc}
*/
public function close()
{
$this->handler->handleBatch($this->buffer);
}
}

@ -0,0 +1,95 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* Buffers all records until a certain level is reached
*
* The advantage of this approach is that you don't get any clutter in your log files.
* Only requests which actually trigger an error (or whatever your actionLevel is) will be
* in the logs, but they will contain all records, not only those above the level threshold.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class FingersCrossedHandler extends AbstractHandler
{
protected $handler;
protected $actionLevel;
protected $buffering = true;
protected $bufferSize;
protected $buffer = array();
protected $stopBuffering;
/**
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
* @param int $actionLevel The minimum logging level at which this handler will be triggered
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
*/
public function __construct($handler, $actionLevel = Logger::WARNING, $bufferSize = 0, $bubble = true, $stopBuffering = true)
{
$this->handler = $handler;
$this->actionLevel = $actionLevel;
$this->bufferSize = $bufferSize;
$this->bubble = $bubble;
$this->stopBuffering = $stopBuffering;
}
/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
return true;
}
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
if ($this->buffering) {
$this->buffer[] = $record;
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
array_shift($this->buffer);
}
if ($record['level'] >= $this->actionLevel) {
if ($this->stopBuffering) {
$this->buffering = false;
}
if (!$this->handler instanceof HandlerInterface) {
$this->handler = call_user_func($this->handler, $record, $this);
}
if (!$this->handler instanceof HandlerInterface) {
throw new \RuntimeException("The factory callback should return a HandlerInterface");
}
$this->handler->handleBatch($this->buffer);
$this->buffer = array();
}
} else {
$this->handler->handle($record);
}
return false === $this->bubble;
}
/**
* Resets the state of the handler. Stops forwarding records to the wrapped handler.
*/
public function reset()
{
$this->buffering = true;
}
}

@ -0,0 +1,159 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Formatter\WildfireFormatter;
/**
* Simple FirePHP Handler (http://www.firephp.org/), which uses the Wildfire protocol.
*
* @author Eric Clemmons (@ericclemmons) <eric@uxdriven.com>
*/
class FirePHPHandler extends AbstractProcessingHandler
{
/**
* WildFire JSON header message format
*/
const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
/**
* FirePHP structure for parsing messages & their presentation
*/
const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
/**
* Must reference a "known" plugin, otherwise headers won't display in FirePHP
*/
const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3';
/**
* Header prefix for Wildfire to recognize & parse headers
*/
const HEADER_PREFIX = 'X-Wf';
/**
* Whether or not Wildfire vendor-specific headers have been generated & sent yet
*/
protected static $initialized = false;
/**
* Shared static message index between potentially multiple handlers
* @var int
*/
protected static $messageIndex = 1;
protected $sendHeaders = true;
/**
* Base header creation function used by init headers & record headers
*
* @param array $meta Wildfire Plugin, Protocol & Structure Indexes
* @param string $message Log message
* @return array Complete header string ready for the client as key and message as value
*/
protected function createHeader(array $meta, $message)
{
$header = sprintf('%s-%s', self::HEADER_PREFIX, join('-', $meta));
return array($header => $message);
}
/**
* Creates message header from record
*
* @see createHeader()
* @param array $record
* @return string
*/
protected function createRecordHeader(array $record)
{
// Wildfire is extensible to support multiple protocols & plugins in a single request,
// but we're not taking advantage of that (yet), so we're using "1" for simplicity's sake.
return $this->createHeader(
array(1, 1, 1, self::$messageIndex++),
$record['formatted']
);
}
/**
* {@inheritDoc}
*/
protected function getDefaultFormatter()
{
return new WildfireFormatter();
}
/**
* Wildfire initialization headers to enable message parsing
*
* @see createHeader()
* @see sendHeader()
* @return array
*/
protected function getInitHeaders()
{
// Initial payload consists of required headers for Wildfire
return array_merge(
$this->createHeader(array('Protocol', 1), self::PROTOCOL_URI),
$this->createHeader(array(1, 'Structure', 1), self::STRUCTURE_URI),
$this->createHeader(array(1, 'Plugin', 1), self::PLUGIN_URI)
);
}
/**
* Send header string to the client
*
* @param string $header
* @param string $content
*/
protected function sendHeader($header, $content)
{
if (!headers_sent() && $this->sendHeaders) {
header(sprintf('%s: %s', $header, $content));
}
}
/**
* Creates & sends header for a record, ensuring init headers have been sent prior
*
* @see sendHeader()
* @see sendInitHeaders()
* @param array $record
*/
protected function write(array $record)
{
// WildFire-specific headers must be sent prior to any messages
if (!self::$initialized) {
$this->sendHeaders = $this->headersAccepted();
foreach ($this->getInitHeaders() as $header => $content) {
$this->sendHeader($header, $content);
}
self::$initialized = true;
}
$header = $this->createRecordHeader($record);
$this->sendHeader(key($header), current($header));
}
/**
* Verifies if the headers are accepted by the current user agent
*
* @return Boolean
*/
protected function headersAccepted()
{
return !isset($_SERVER['HTTP_USER_AGENT']) || preg_match('{\bFirePHP/\d+\.\d+\b}', $_SERVER['HTTP_USER_AGENT']);
}
}

@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
/**
* Forwards records to multiple handlers
*
* @author Lenar Lõhmus <lenar@city.ee>
*/
class GroupHandler extends AbstractHandler
{
protected $handlers;
/**
* @param array $handlers Array of Handlers.
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(array $handlers, $bubble = true)
{
foreach ($handlers as $handler) {
if (!$handler instanceof HandlerInterface) {
throw new \InvalidArgumentException('The first argument of the GroupHandler must be an array of HandlerInterface instances.');
}
}
$this->handlers = $handlers;
$this->bubble = $bubble;
}
/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
foreach ($this->handlers as $handler) {
if ($handler->isHandling($record)) {
return true;
}
}
return false;
}
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
foreach ($this->handlers as $handler) {
$handler->handle($record);
}
return false === $this->bubble;
}
/**
* {@inheritdoc}
*/
public function handleBatch(array $records)
{
foreach ($this->handlers as $handler) {
$handler->handleBatch($records);
}
}
}

@ -0,0 +1,77 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Formatter\FormatterInterface;
/**
* Interface that all Monolog Handlers must implement
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface HandlerInterface
{
/**
* Checks whether the given record will be handled by this handler.
*
* This is mostly done for performance reasons, to avoid calling processors for nothing.
*
* @return Boolean
*/
function isHandling(array $record);
/**
* Handles a record.
*
* The return value of this function controls the bubbling process of the handler stack.
*
* @param array $record The record to handle
* @return Boolean True means that this handler handled the record, and that bubbling is not permitted.
* False means the record was either not processed or that this handler allows bubbling.
*/
function handle(array $record);
/**
* Handles a set of records at once.
*
* @param array $records The records to handle (an array of record arrays)
*/
function handleBatch(array $records);
/**
* Adds a processor in the stack.
*
* @param callable $callback
*/
function pushProcessor($callback);
/**
* Removes the processor on top of the stack and returns it.
*
* @return callable
*/
function popProcessor();
/**
* Sets the formatter.
*
* @param FormatterInterface $formatter
*/
function setFormatter(FormatterInterface $formatter);
/**
* Gets the formatter.
*
* @return FormatterInterface
*/
function getFormatter();
}

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
/**
* Base class for all mail handlers
*
* @author Gyula Sallai
*/
abstract class MailHandler extends AbstractProcessingHandler
{
/**
* {@inheritdoc}
*/
public function handleBatch(array $records)
{
$messages = array();
foreach ($records as $record) {
if ($record['level'] < $this->level) {
continue;
}
$messages[] = $this->processRecord($record);
}
if (!empty($messages)) {
$this->send((string) $this->getFormatter()->formatBatch($messages));
}
}
/**
* Send a mail with the given content
*
* @param string $content
*/
abstract protected function send($content);
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$this->send((string) $record['formatted']);
}
}

@ -0,0 +1,49 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* NativeMailerHandler uses the mail() function to send the emails
*
* @author Christophe Coevoet <stof@notk.org>
*/
class NativeMailerHandler extends MailHandler
{
protected $to;
protected $subject;
protected $headers;
/**
* @param string $to The receiver of the mail
* @param string $subject The subject of the mail
* @param string $from The sender of the mail
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($to, $subject, $from, $level = Logger::ERROR, $bubble = true)
{
parent::__construct($level, $bubble);
$this->to = $to;
$this->subject = $subject;
$this->headers = sprintf("From: %s\r\nContent-type: text/plain; charset=utf-8\r\n", $from);
}
/**
* {@inheritdoc}
*/
protected function send($content)
{
mail($this->to, $this->subject, wordwrap($content, 70), $this->headers);
}
}

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* Blackhole
*
* Any record it can handle will be thrown away. This can be used
* to put on top of an existing stack to override it temporarily.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class NullHandler extends AbstractHandler
{
/**
* {@inheritdoc}
*/
public function handle(array $record)
{
if ($record['level'] < $this->level) {
return false;
}
return true;
}
}

@ -0,0 +1,109 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* Stores logs to files that are rotated every day and a limited number of files are kept.
*
* This rotation is only intended to be used as a workaround. Using logrotate to
* handle the rotation is strongly encouraged when you can use it.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class RotatingFileHandler extends StreamHandler
{
protected $filename;
protected $maxFiles;
protected $mustRotate;
/**
* @param string $filename
* @param integer $maxFiles The maximal amount of files to keep (0 means unlimited)
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($filename, $maxFiles = 0, $level = Logger::DEBUG, $bubble = true)
{
$this->filename = $filename;
$this->maxFiles = (int) $maxFiles;
$fileInfo = pathinfo($this->filename);
$timedFilename = $fileInfo['dirname'].'/'.$fileInfo['filename'].'-'.date('Y-m-d');
if (!empty($fileInfo['extension'])) {
$timedFilename .= '.'.$fileInfo['extension'];
}
// disable rotation upfront if files are unlimited
if (0 === $this->maxFiles) {
$this->mustRotate = false;
}
parent::__construct($timedFilename, $level, $bubble);
}
/**
* {@inheritdoc}
*/
public function close()
{
parent::close();
if (true === $this->mustRotate) {
$this->rotate();
}
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
// on the first record written, if the log is new, we should rotate (once per day)
if (null === $this->mustRotate) {
$this->mustRotate = !file_exists($this->url);
}
parent::write($record);
}
/**
* Rotates the files.
*/
protected function rotate()
{
$fileInfo = pathinfo($this->filename);
$glob = $fileInfo['dirname'].'/'.$fileInfo['filename'].'-*';
if (!empty($fileInfo['extension'])) {
$glob .= '.'.$fileInfo['extension'];
}
$iterator = new \GlobIterator($glob);
$count = $iterator->count();
if ($this->maxFiles >= $count) {
// no files to remove
return;
}
// Sorting the files by name to remove the older ones
$array = iterator_to_array($iterator);
usort($array, function($a, $b) {
return strcmp($b->getFilename(), $a->getFilename());
});
foreach (array_slice($array, $this->maxFiles) as $file) {
if ($file->isWritable()) {
unlink($file->getRealPath());
}
}
}
}

@ -0,0 +1,72 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Formatter\SimpleFormatter;
use Monolog\Logger;
/**
* Stores to any stream resource
*
* Can be used to store into php://stderr, remote and local files, etc.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class StreamHandler extends AbstractProcessingHandler
{
protected $stream;
protected $url;
/**
* @param string $stream
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($stream, $level = Logger::DEBUG, $bubble = true)
{
parent::__construct($level, $bubble);
if (is_resource($stream)) {
$this->stream = $stream;
} else {
$this->url = $stream;
}
}
/**
* {@inheritdoc}
*/
public function close()
{
if (is_resource($this->stream)) {
fclose($this->stream);
}
$this->stream = null;
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if (null === $this->stream) {
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$this->stream = @fopen($this->url, 'a');
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened; it may be invalid or not writable.', $this->url));
}
}
fwrite($this->stream, (string) $record['formatted']);
}
}

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* SwiftMailerHandler uses Swift_Mailer to send the emails
*
* @author Gyula Sallai
*/
class SwiftMailerHandler extends MailHandler
{
protected $mailer;
protected $message;
/**
* @param \Swift_Mailer $mailer The mailer to use
* @param callback|\Swift_Message $message An example message for real messages, only the body will be replaced
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, $bubble = true)
{
parent::__construct($level, $bubble);
$this->mailer = $mailer;
if (!$message instanceof \Swift_Message && is_callable($message)) {
$message = call_user_func($message);
}
if (!$message instanceof \Swift_Message) {
throw new \InvalidArgumentException('You must provide either a Swift_Message instance or a callback returning it');
}
$this->message = $message;
}
/**
* {@inheritdoc}
*/
protected function send($content)
{
$message = clone $this->message;
$message->setBody($content);
$this->mailer->send($message);
}
}

@ -0,0 +1,109 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Formatter\SimpleFormatter;
use Monolog\Logger;
/**
* Logs to syslog service.
*
* usage example:
*
* $log = new Logger('application');
* $syslog = new SyslogHandler('myfacility', 'local6');
* $formatter = new LineFormatter("%channel%.%level_name%: %message% %extra%");
* $syslog->setFormatter($formatter);
* $log->pushHandler($syslog);
*
* @author Sven Paulus <sven@karlsruhe.org>
*/
class SyslogHandler extends AbstractProcessingHandler
{
/**
* Translates Monolog log levels to syslog log priorities.
*/
private $logLevels = array(
Logger::DEBUG => LOG_DEBUG,
Logger::INFO => LOG_INFO,
Logger::WARNING => LOG_WARNING,
Logger::ERROR => LOG_ERR,
Logger::CRITICAL => LOG_CRIT,
Logger::ALERT => LOG_ALERT,
);
/**
* List of valid log facility names.
*/
private $facilities = array(
'auth' => LOG_AUTH,
'authpriv' => LOG_AUTHPRIV,
'cron' => LOG_CRON,
'daemon' => LOG_DAEMON,
'kern' => LOG_KERN,
'lpr' => LOG_LPR,
'mail' => LOG_MAIL,
'news' => LOG_NEWS,
'syslog' => LOG_SYSLOG,
'user' => LOG_USER,
'uucp' => LOG_UUCP,
);
/**
* @param string $ident
* @param mixed $facility
* @param integer $level The minimum logging level at which this handler will be triggered
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
{
parent::__construct($level, $bubble);
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->facilities['local0'] = LOG_LOCAL0;
$this->facilities['local1'] = LOG_LOCAL1;
$this->facilities['local2'] = LOG_LOCAL2;
$this->facilities['local3'] = LOG_LOCAL3;
$this->facilities['local4'] = LOG_LOCAL4;
$this->facilities['local5'] = LOG_LOCAL5;
$this->facilities['local6'] = LOG_LOCAL6;
$this->facilities['local7'] = LOG_LOCAL7;
}
// convert textual description of facility to syslog constant
if (array_key_exists(strtolower($facility), $this->facilities)) {
$facility = $this->facilities[strtolower($facility)];
} else if (!in_array($facility, array_values($this->facilities), true)) {
throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
}
if (!openlog($ident, LOG_PID, $facility)) {
throw new \LogicException('Can\'t open syslog for ident "'.$ident.'" and facility "'.$facility.'"');
}
}
/**
* {@inheritdoc}
*/
public function close()
{
closelog();
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
syslog($this->logLevels[$record['level']], (string) $record['formatted']);
}
}

@ -0,0 +1,120 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
/**
* Used for testing purposes.
*
* It records all records and gives you access to them for verification.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class TestHandler extends AbstractProcessingHandler
{
protected $records = array();
protected $recordsByLevel = array();
public function getRecords()
{
return $this->records;
}
public function hasAlert($record)
{
return $this->hasRecord($record, Logger::ALERT);
}
public function hasCritical($record)
{
return $this->hasRecord($record, Logger::CRITICAL);
}
public function hasError($record)
{
return $this->hasRecord($record, Logger::ERROR);
}
public function hasWarning($record)
{
return $this->hasRecord($record, Logger::WARNING);
}
public function hasInfo($record)
{
return $this->hasRecord($record, Logger::INFO);
}
public function hasDebug($record)
{
return $this->hasRecord($record, Logger::DEBUG);
}
public function hasAlertRecords()
{
return isset($this->recordsByLevel[Logger::ALERT]);
}
public function hasCriticalRecords()
{
return isset($this->recordsByLevel[Logger::CRITICAL]);
}
public function hasErrorRecords()
{
return isset($this->recordsByLevel[Logger::ERROR]);
}
public function hasWarningRecords()
{
return isset($this->recordsByLevel[Logger::WARNING]);
}
public function hasInfoRecords()
{
return isset($this->recordsByLevel[Logger::INFO]);
}
public function hasDebugRecords()
{
return isset($this->recordsByLevel[Logger::DEBUG]);
}
protected function hasRecord($record, $level)
{
if (!isset($this->recordsByLevel[$level])) {
return false;
}
if (is_array($record)) {
$record = $record['message'];
}
foreach ($this->recordsByLevel[$level] as $rec) {
if ($rec['message'] === $record) {
return true;
}
}
return false;
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$this->recordsByLevel[$record['level']][] = $record;
$this->records[] = $record;
}
}

@ -0,0 +1,394 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\StreamHandler;
/**
* Monolog log channel
*
* It contains a stack of Handlers and a stack of Processors,
* and uses them to store records that are added to it.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class Logger
{
/**
* Detailed debug information
*/
const DEBUG = 100;
/**
* Interesting events
*
* Examples: User logs in, SQL logs.
*/
const INFO = 200;
/**
* Exceptional occurences that are not errors
*
* Examples: Use of deprecated APIs, poor use of an API,
* undesirable things that are not necessarily wrong.
*/
const WARNING = 300;
/**
* Runtime errors
*/
const ERROR = 400;
/**
* Critical conditions
*
* Example: Application component unavailable, unexpected exception.
*/
const CRITICAL = 500;
/**
* Action must be taken immediately
*
* Example: Entire website down, database unavailable, etc.
* This should trigger the SMS alerts and wake you up.
*/
const ALERT = 550;
protected static $levels = array(
100 => 'DEBUG',
200 => 'INFO',
300 => 'WARNING',
400 => 'ERROR',
500 => 'CRITICAL',
550 => 'ALERT',
);
protected $name;
/**
* The handler stack
*
* @var array of Monolog\Handler\HandlerInterface
*/
protected $handlers = array();
protected $processors = array();
/**
* @param string $name The logging channel
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Pushes an handler on the stack.
*
* @param HandlerInterface $handler
*/
public function pushHandler(HandlerInterface $handler)
{
array_unshift($this->handlers, $handler);
}
/**
* Pops an handler from the stack
*
* @return HandlerInterface
*/
public function popHandler()
{
if (!$this->handlers) {
throw new \LogicException('You tried to pop from an empty handler stack.');
}
return array_shift($this->handlers);
}
/**
* Adds a processor in the stack.
*
* @param callable $callback
*/
public function pushProcessor($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
}
array_unshift($this->processors, $callback);
}
/**
* Removes the processor on top of the stack and returns it.
*
* @return callable
*/
public function popProcessor()
{
if (!$this->processors) {
throw new \LogicException('You tried to pop from an empty processor stack.');
}
return array_shift($this->processors);
}
/**
* Adds a log record.
*
* @param integer $level The logging level
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addRecord($level, $message, array $context = array())
{
if (!$this->handlers) {
$this->pushHandler(new StreamHandler('php://stderr', self::DEBUG));
}
$record = array(
'message' => (string) $message,
'context' => $context,
'level' => $level,
'level_name' => self::getLevelName($level),
'channel' => $this->name,
'datetime' => new \DateTime(),
'extra' => array(),
);
// check if any message will handle this message
$handlerKey = null;
foreach ($this->handlers as $key => $handler) {
if ($handler->isHandling($record)) {
$handlerKey = $key;
break;
}
}
// none found
if (null === $handlerKey) {
return false;
}
// found at least one, process message and dispatch it
foreach ($this->processors as $processor) {
$record = call_user_func($processor, $record);
}
while (isset($this->handlers[$handlerKey]) &&
false === $this->handlers[$handlerKey]->handle($record)) {
$handlerKey++;
}
return true;
}
/**
* Adds a log record at the DEBUG level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addDebug($message, array $context = array())
{
return $this->addRecord(self::DEBUG, $message, $context);
}
/**
* Adds a log record at the INFO level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addInfo($message, array $context = array())
{
return $this->addRecord(self::INFO, $message, $context);
}
/**
* Adds a log record at the WARNING level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addWarning($message, array $context = array())
{
return $this->addRecord(self::WARNING, $message, $context);
}
/**
* Adds a log record at the ERROR level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addError($message, array $context = array())
{
return $this->addRecord(self::ERROR, $message, $context);
}
/**
* Adds a log record at the CRITICAL level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addCritical($message, array $context = array())
{
return $this->addRecord(self::CRITICAL, $message, $context);
}
/**
* Adds a log record at the ALERT level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addAlert($message, array $context = array())
{
return $this->addRecord(self::ALERT, $message, $context);
}
/**
* Gets the name of the logging level.
*
* @param integer $level
* @return string
*/
public static function getLevelName($level)
{
return self::$levels[$level];
}
// ZF Logger Compat
/**
* Adds a log record at the DEBUG level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function debug($message, array $context = array())
{
return $this->addRecord(self::DEBUG, $message, $context);
}
/**
* Adds a log record at the INFO level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function info($message, array $context = array())
{
return $this->addRecord(self::INFO, $message, $context);
}
/**
* Adds a log record at the INFO level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function notice($message, array $context = array())
{
return $this->addRecord(self::INFO, $message, $context);
}
/**
* Adds a log record at the WARNING level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function warn($message, array $context = array())
{
return $this->addRecord(self::WARNING, $message, $context);
}
/**
* Adds a log record at the ERROR level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function err($message, array $context = array())
{
return $this->addRecord(self::ERROR, $message, $context);
}
/**
* Adds a log record at the CRITICAL level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function crit($message, array $context = array())
{
return $this->addRecord(self::CRITICAL, $message, $context);
}
/**
* Adds a log record at the ALERT level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function alert($message, array $context = array())
{
return $this->addRecord(self::ALERT, $message, $context);
}
/**
* Adds a log record at the ALERT level.
*
* This method allows to have an easy ZF compatibility.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function emerg($message, array $context = array())
{
return $this->addRecord(self::ALERT, $message, $context);
}
}

@ -0,0 +1,58 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Injects line/file:class/function where the log message came from
*
* Warning: This only works if the handler processes the logs directly.
* If you put the processor on a handler that is behind a FingersCrossedHandler
* for example, the processor will only be called once the trigger level is reached,
* and all the log records will have the same file/line/.. data from the call that
* triggered the FingersCrossedHandler.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class IntrospectionProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$trace = debug_backtrace();
// skip first since it's always the current method
array_shift($trace);
// the call_user_func call is also skipped
array_shift($trace);
$i = 0;
while (isset($trace[$i]['class']) && false !== strpos($trace[$i]['class'], 'Monolog\\')) {
$i++;
}
// we should have the call source now
$record['extra'] = array_merge(
$record['extra'],
array(
'file' => isset($trace[$i-1]['file']) ? $trace[$i-1]['file'] : null,
'line' => isset($trace[$i-1]['line']) ? $trace[$i-1]['line'] : null,
'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null,
'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null,
)
);
return $record;
}
}

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Injects memory_get_peak_usage in all records
*
* @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen
*/
class MemoryPeakUsageProcessor extends MemoryProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$bytes = memory_get_peak_usage($this->realUsage);
$formatted = self::formatBytes($bytes);
$record['extra'] = array_merge(
$record['extra'],
array(
'memory_peak_usage' => $formatted,
)
);
return $record;
}
}

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Some methods that are common for all memory processors
*
* @author Rob Jensen
*/
abstract class MemoryProcessor
{
protected $realUsage;
/**
* @param boolean $realUsage
*/
public function __construct($realUsage = true)
{
$this->realUsage = (boolean) $realUsage;
}
/**
* Formats bytes into a human readable string
*
* @param int $bytes
* @return string
*/
protected static function formatBytes($bytes)
{
$bytes = (int) $bytes;
if ($bytes > 1024*1024) {
return round($bytes/1024/1024, 2).' MB';
} elseif ($bytes > 1024) {
return round($bytes/1024, 2).' KB';
}
return $bytes . ' B';
}
}

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Injects memory_get_usage in all records
*
* @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen
*/
class MemoryUsageProcessor extends MemoryProcessor
{
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
$bytes = memory_get_usage($this->realUsage);
$formatted = self::formatBytes($bytes);
$record['extra'] = array_merge(
$record['extra'],
array(
'memory_usage' => $formatted,
)
);
return $record;
}
}

@ -0,0 +1,60 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Injects url/method and remote IP of the current web request in all records
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class WebProcessor
{
protected $serverData;
/**
* @param mixed $serverData array or object w/ ArrayAccess that provides access to the $_SERVER data
*/
public function __construct($serverData = null)
{
if (null === $serverData) {
$this->serverData =& $_SERVER;
} elseif (is_array($serverData) || $serverData instanceof \ArrayAccess) {
$this->serverData = $serverData;
} else {
throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
}
}
/**
* @param array $record
* @return array
*/
public function __invoke(array $record)
{
// skip processing if for some reason request data
// is not present (CLI or wonky SAPIs)
if (!isset($this->serverData['REQUEST_URI'])) {
return $record;
}
$record['extra'] = array_merge(
$record['extra'],
array(
'url' => $this->serverData['REQUEST_URI'],
'ip' => $this->serverData['REMOTE_ADDR'],
'http_method' => $this->serverData['REQUEST_METHOD'],
)
);
return $record;
}
}

@ -0,0 +1,45 @@
<?php
/**
* Install database. Provides access to the Database class and allows to add hooks
* for logging, testing, etc during installation.
*
*
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class iDatabase extends Database
{
private static $is_logging = true;
static function is_logging()
{
return self::$is_logging;
}
static function set_is_logging($value)
{
self::$is_logging = $value;
}
static function select_db($database_name, $connection = null)
{
if (self::is_logging()) {
Log::notice(__FUNCTION__ . ' ' . $database_name, Log::frame(1));
}
parent::select_db($database_name, $connection);
}
static function query($query, $connection = null, $file = null, $line = null)
{
if (self::is_logging()) {
$query = str_replace("\n", '', $query);
Log::notice(__FUNCTION__ . ' ' . $query, Log::frame(1));
}
parent::query($query, $connection, $file, $line);
}
}

@ -37,12 +37,16 @@ if (!function_exists('version_compare') || version_compare( phpversion(), REQUIR
/* INITIALIZATION SECTION */
ob_implicit_flush(true);
session_start();
// Including necessary libraries.
require_once '../inc/lib/main_api.lib.php';
require_once api_get_path(LIBRARY_PATH).'database.lib.php';
require_once api_get_path(LIBRARY_PATH).'log.class.php';
require_once 'install.lib.php';
require_once 'install.class.php';
require_once 'i_database.class.php';
// The function api_get_setting() might be called within the installation scripts.
// We need to provide some limited support for it through initialization of the
@ -100,6 +104,11 @@ header('Content-Type: text/html; charset='. api_get_system_encoding());
// Setting the error reporting levels.
error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
/**
* @todo: remove that
*/
error_reporting(E_ALL);
// Overriding the timelimit (for large campusses that have to be migrated).
@set_time_limit(0);
@ -155,13 +164,13 @@ if (!empty($_POST['updatePath'])) {
$proposedUpdatePath = $_POST['updatePath'];
}
if ($_POST['step2_install'] || $_POST['step2_update_8'] || $_POST['step2_update_6']) {
if ($_POST['step2_install']) {
if (@$_POST['step2_install'] || @$_POST['step2_update_8'] || @$_POST['step2_update_6']) {
if (@$_POST['step2_install']) {
$installType = 'new';
$_POST['step2'] = 1;
} else {
$installType = 'update';
if ($_POST['step2_update_8']) {
if (@$_POST['step2_update_8']) {
$emptyUpdatePath = false;
$proposedUpdatePath = api_add_trailing_slash(empty($_POST['updatePath']) ? api_get_path(SYS_PATH) : $_POST['updatePath']);
if (file_exists($proposedUpdatePath)) {
@ -194,7 +203,7 @@ if ($_POST['step2_install'] || $_POST['step2_update_8'] || $_POST['step2_update_
}
}
}
} elseif ($_POST['step1']) {
} elseif (@$_POST['step1']) {
$_POST['updatePath'] = '';
$installType = '';
$updateFromConfigFile = '';
@ -484,10 +493,12 @@ if ($encryptPassForm == '1') {
echo '<div class="page-header"><h1>'.get_lang('ChamiloInstallation').' &ndash; '.get_lang('Version_').' '.$new_version.'</h1></div>';
$instalation_type_label = '';
if ($installType == 'new')
if ($installType == 'new'){
$instalation_type_label = get_lang('NewInstallation');
elseif ($installType == 'update')
}elseif ($installType == 'update') {
$update_from_version = isset($update_from_version) ? $update_from_version : null;
$instalation_type_label = get_lang('UpdateFromDokeosVersion').(is_array($update_from_version) ? implode('|', $update_from_version) : '');
}
if (!empty($instalation_type_label)) {
echo "<h2>$instalation_type_label</h2><hr />";
}
@ -538,13 +549,13 @@ if ($encryptPassForm == '1') {
<input type="hidden" name="old_version" value="<?php echo api_htmlentities($my_old_version, ENT_QUOTES); ?>" />
<input type="hidden" name="new_version" value="<?php echo api_htmlentities($new_version, ENT_QUOTES); ?>" />
<?php
if ($_POST['step2']) {
if (@$_POST['step2']) {
//STEP 3 : LICENSE
display_license_agreement();
} elseif ($_POST['step3']) {
} elseif (@$_POST['step3']) {
//STEP 4 : MYSQL DATABASE SETTINGS
display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm);
} elseif ($_POST['step4']) {
} elseif (@$_POST['step4']) {
//STEP 5 : CONFIGURATION SETTINGS
//if update, try getting settings from the database...
@ -612,7 +623,7 @@ if ($_POST['step2']) {
}
display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm);
} elseif ($_POST['step5']) {
} elseif (@$_POST['step5']) {
//STEP 6 : LAST CHECK BEFORE INSTALL
?>
<div class="RequirementHeading">
@ -700,7 +711,7 @@ if ($_POST['step2']) {
</table>
<?php
} elseif ($_POST['step6']) {
} elseif (@$_POST['step6']) {
//STEP 6 : INSTALLATION PROCESS
@ -721,7 +732,7 @@ if ($_POST['step2']) {
$_configuration['main_database'] = $dbNameForm;
//$urlAppendPath = get_config_param('urlAppend');
error_log('Starting migration process from '.$my_old_version.' ('.time().')', 0);
Log::notice('Starting migration process from '.$my_old_version.' ('.time().')');
if ($userPasswordCrypted == '1') {
$userPasswordCrypted = 'md5';
@ -814,7 +825,7 @@ if ($_POST['step2']) {
include 'install_files.inc.php';
}
$current_step = 7;
display_after_install_message($installType, $nbr_courses);
display_after_install_message($installType);
} elseif ($_POST['step1'] || $badUpdatePath) {
//STEP 1 : REQUIREMENTS

@ -0,0 +1,16 @@
<?php
/**
* Description of install
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class Install
{
static function message($message)
{
echo '<div>' . $message . '</div>';
}
}

@ -516,7 +516,7 @@ function get_config_param($param, $updatePath = '') {
$configFile[$variable] = $value;
$a = explode("'", $variable);
$key_tmp = $a[1];
$key_tmp = isset($a[1]) ? $a[1] : null;
if ($key_tmp == $param) {
$val = $value;
}
@ -1942,7 +1942,7 @@ function display_configuration_settings_form($installType, $urlForm, $languageFo
/**
* After installation is completed (step 6), this message is displayed.
*/
function display_after_install_message($installType, $nbr_courses) {
function display_after_install_message($installType) {
?>
<div class="RequirementHeading">
<h2><?php echo display_step_sequence() . get_lang('CfgSetting'); ?></h2>

@ -189,6 +189,19 @@ INSERT INTO settings_options(variable,value,display_text) VALUES ('page_after_lo
ALTER TABLE settings_current ADD COLUMN access_url_locked INTEGER NOT NULL DEFAULT 0;
-- skills
CREATE TABLE IF NOT EXISTS skill ( id int NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, short_code varchar(100) NOT NULL, description TEXT NOT NULL, access_url_id int NOT NULL, icon varchar(255) NOT NULL, PRIMARY KEY (id));
INSERT INTO skill (name) VALUES ('Root');
CREATE TABLE IF NOT EXISTS skill_rel_gradebook ( id int NOT NULL AUTO_INCREMENT, gradebook_id int NOT NULL, skill_id int NOT NULL, type varchar(10) NOT NULL, PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS skill_rel_skill ( skill_id int NOT NULL, parent_id int NOT NULL, relation_type int NOT NULL, level int NOT NULL);
INSERT INTO skill_rel_skill VALUES(1, 0, 0, 0);
CREATE TABLE IF NOT EXISTS skill_rel_user ( id int NOT NULL AUTO_INCREMENT, user_id int NOT NULL, skill_id int NOT NULL, acquired_skill_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',assigned_by int NOT NULL,PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS skill_profile ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL, PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS skill_rel_profile ( id INTEGER NOT NULL AUTO_INCREMENT, skill_id INTEGER NOT NULL, profile_id INTEGER NOT NULL, PRIMARY KEY (id));
-- Removing use_document_title
DELETE FROM settings_current WHERE variable = 'use_document_title';
DELETE FROM settings_options WHERE variable = 'use_document_title';

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
*
@ -7,64 +8,65 @@
* Only updates the main/inc/conf/configuration.php file with the new version use only from 1.8.8.1 to 1.8.8.2 (with no DB changes)
* @package chamilo.install
*/
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH).'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w');
$found_version_old = false;
$found_stable_old = false;
$found_version = false;
$found_stable = false;
$found_software_name = false;
$found_software_url = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version_old = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
$ignore = true;
} elseif (stripos($line, '$_configuration[\'system_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'system_version\'] = \''.$new_version.'\';'."\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable_old = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n";
$ignore = true;
} elseif (stripos($line, '$_configuration[\'system_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'system_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n";
} elseif (stripos($line, '$_configuration[\'software_name\']') !== false) {
$found_software_name = true;
$line = '$_configuration[\'software_name\'] = \''.$software_name.'\';'."\r\n";
} elseif (stripos($line, '$_configuration[\'software_url\']') !== false) {
$found_software_url = true;
$line = '$_configuration[\'software_url\'] = \''.$software_url.'\';'."\r\n";
} elseif (stripos($line,'$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} elseif (stripos($line, '?>') !== false) {
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'system_version\'] = \''.$new_version.'\';'."\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'system_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
}
if (!$found_software_name) {
fwrite($fh, '$_configuration[\'software_name\'] = \''.$software_name.'\';'."\r\n");
}
if (!$found_software_url) {
fwrite($fh, '$_configuration[\'software_url\'] = \''.$software_url.'\';'."\r\n");
}
fwrite($fh, '?>');
fclose($fh);
Log::notice("Starting " . basename(__FILE__));
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH) . 'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH) . 'configuration.php', 'w');
$found_version_old = false;
$found_stable_old = false;
$found_version = false;
$found_stable = false;
$found_software_name = false;
$found_software_url = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version_old = true;
$line = '$_configuration[\'dokeos_version\'] = \'' . $new_version . '\';' . "\r\n";
$ignore = true;
} elseif (stripos($line, '$_configuration[\'system_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'system_version\'] = \'' . $new_version . '\';' . "\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable_old = true;
$line = '$_configuration[\'dokeos_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n";
$ignore = true;
} elseif (stripos($line, '$_configuration[\'system_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'system_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n";
} elseif (stripos($line, '$_configuration[\'software_name\']') !== false) {
$found_software_name = true;
$line = '$_configuration[\'software_name\'] = \'' . $software_name . '\';' . "\r\n";
} elseif (stripos($line, '$_configuration[\'software_url\']') !== false) {
$found_software_url = true;
$line = '$_configuration[\'software_url\'] = \'' . $software_url . '\';' . "\r\n";
} elseif (stripos($line, '$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \'' . ($userPasswordCrypted) . '\';' . "\r\n";
} elseif (stripos($line, '?>') !== false) {
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'system_version\'] = \'' . $new_version . '\';' . "\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'system_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n");
}
if (!$found_software_name) {
fwrite($fh, '$_configuration[\'software_name\'] = \'' . $software_name . '\';' . "\r\n");
}
if (!$found_software_url) {
fwrite($fh, '$_configuration[\'software_url\'] = \'' . $software_url . '\';' . "\r\n");
}
fwrite($fh, '?>');
fclose($fh);
} else {
echo 'You are not allowed here !';
echo 'You are not allowed here !';
}

File diff suppressed because it is too large Load Diff

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -16,194 +17,196 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
// Check if we come from index.php or update_courses.php - otherwise display error msg
if (defined('SYSTEM_INSTALLATION')) {
// Check if the current Dokeos install is eligible for update
if (!file_exists('../inc/conf/configuration.php')) {
echo '<strong>'.get_lang('Error').' !</strong> Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
'.get_lang('PleasGoBackToStep1').'.
<p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
// Check if the current Dokeos install is eligible for update
if (!file_exists('../inc/conf/configuration.php')) {
echo '<strong>' . get_lang('Error') . ' !</strong> Dokeos ' . implode('|', $updateFromVersion) . ' ' . get_lang('HasNotBeenFound') . '.<br /><br />
' . get_lang('PleasGoBackToStep1') . '.
<p><button type="submit" class="back" name="step1" value="&lt; ' . get_lang('Back') . '">' . get_lang('Back') . '</button></p>
</td></tr></table></form></body></html>';
exit ();
}
$_configuration['db_glue'] = get_config_param('dbGlu');
if ($singleDbForm) {
$_configuration['table_prefix'] = get_config_param('courseTablePrefix');
$_configuration['main_database'] = get_config_param('mainDbName');
$_configuration['db_prefix'] = get_config_param('dbNamePrefix');
}
$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
$dbScormForm = $dbPrefixForm.$dbScormForm;
}
if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
$dbScormForm = $dbPrefixForm.'scorm';
}
/* Normal upgrade procedure: start by updating main, statistic, user databases */
// If this script has been included by index.php, not update_courses.php, so
// that we want to change the main databases as well...
$only_test = false;
$log = 0;
if (defined('SYSTEM_INSTALLATION')) {
if ($singleDbForm) {
$dbStatsForm = $dbNameForm;
$dbScormForm = $dbNameForm;
$dbUserForm = $dbNameForm;
}
/**
* Update the databases "pre" migration
*/
include '../lang/english/create_course.inc.php';
if ($languageForm != 'english') {
//languageForm has been escaped in index.php
include '../lang/'.$languageForm.'/create_course.inc.php';
}
// Get the main queries list (m_q_list)
$m_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'main');
if (count($m_q_list) > 0) {
//now use the $m_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
}
}
}
}
}
// Get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'stats');
if (count($s_q_list) > 0) {
// Now use the $s_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
} elseif (!in_array($dbStatsForm, $dblist)) {
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
} else {
Database::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
}
}
}
}
}
// Get the user queries list (u_q_list)
$u_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'user');
if (count($u_q_list) > 0) {
//now use the $u_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
} else {
Database::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
} else {
$res = Database::query($query);
}
}
}
}
// The SCORM database doesn't need a change in the pre-migrate part - ignore
}
$prefix = '';
if ($singleDbForm) {
$prefix = $_configuration['table_prefix'];
}
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'course');
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.0-1.8.2.inc.php'); }
if (Database::num_rows($res) > 0) {
$i = 0;
exit();
}
$_configuration['db_glue'] = get_config_param('dbGlu');
if ($singleDbForm) {
$_configuration['table_prefix'] = get_config_param('courseTablePrefix');
$_configuration['main_database'] = get_config_param('mainDbName');
$_configuration['db_prefix'] = get_config_param('dbNamePrefix');
}
$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
$dbScormForm = $dbPrefixForm . $dbScormForm;
}
if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
$dbScormForm = $dbPrefixForm . 'scorm';
}
/* Normal upgrade procedure: start by updating main, statistic, user databases */
// If this script has been included by index.php, not update_courses.php, so
// that we want to change the main databases as well...
$only_test = false;
$log = 0;
if (defined('SYSTEM_INSTALLATION')) {
if ($singleDbForm) {
$dbStatsForm = $dbNameForm;
$dbScormForm = $dbNameForm;
$dbUserForm = $dbNameForm;
}
/**
* Update the databases "pre" migration
*/
include '../lang/english/create_course.inc.php';
if ($languageForm != 'english') {
//languageForm has been escaped in index.php
include '../lang/' . $languageForm . '/create_course.inc.php';
}
// Get the main queries list (m_q_list)
$m_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'main');
if (count($m_q_list) > 0) {
//now use the $m_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name ' . $dbNameForm . ' is too long, skipping', 0);
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database ' . $dbNameForm . ' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
}
}
}
}
}
// Get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'stats');
if (count($s_q_list) > 0) {
// Now use the $s_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name ' . $dbStatsForm . ' is too long, skipping', 0);
} elseif (!in_array($dbStatsForm, $dblist)) {
error_log('Database ' . $dbStatsForm . ' was not found, skipping', 0);
} else {
Database::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
}
}
}
}
}
// Get the user queries list (u_q_list)
$u_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'user');
if (count($u_q_list) > 0) {
//now use the $u_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name ' . $dbUserForm . ' is too long, skipping', 0);
} elseif (!in_array($dbUserForm, $dblist)) {
error_log('Database ' . $dbUserForm . ' was not found, skipping', 0);
} else {
Database::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
} else {
$res = Database::query($query);
}
}
}
}
// The SCORM database doesn't need a change in the pre-migrate part - ignore
}
$prefix = '';
if ($singleDbForm) {
$prefix = $_configuration['table_prefix'];
}
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-1.8.0-1.8.2-pre.sql', 'course');
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name ' . $dbNameForm . ' is too long, skipping', 0);
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database ' . $dbNameForm . ' was not found, skipping', 0);
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) {
die('Error while querying the courses list in update_db-1.8.0-1.8.2.inc.php');
}
if (Database::num_rows($res) > 0) {
$i = 0;
$list = array();
while($row = Database::fetch_array($res)) {
$list[] = $row;
$i++;
}
foreach ($list as $row_course) {
// Now use the $c_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (!$singleDbForm) { // otherwise just use the main one
Database::select_db($row_course['db_name']);
}
foreach ($c_q_list as $query) {
if ($singleDbForm) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query);
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
}
}
}
}
}
}
}
while ($row = Database::fetch_array($res)) {
$list[] = $row;
$i++;
}
foreach ($list as $row_course) {
// Now use the $c_q_list
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (!$singleDbForm) { // otherwise just use the main one
Database::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query);
}
if ($only_test) {
error_log("Database::query(" . $row_course['db_name'] . ",$query)", 0);
} else {
$res = Database::query($query);
if ($log) {
error_log("In " . $row_course['db_name'] . ", executed: $query", 0);
}
}
}
}
}
}
}
} else {
echo 'You are not allowed here !';
echo 'You are not allowed here !';
}

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
// Check if we come from index.php or update_courses.php - otherwise display error msg
if (defined('SYSTEM_INSTALLATION')) {
@ -183,6 +184,7 @@ if (defined('SYSTEM_INSTALLATION')) {
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) { //otherwise just use the main one

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
// Check if we come from index.php or update_courses.php - otherwise display error msg
if (defined('SYSTEM_INSTALLATION')) {
@ -183,6 +184,7 @@ if (defined('SYSTEM_INSTALLATION')) {
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.4';
$new_file_version = '1.8.5';
@ -190,6 +191,7 @@ if (defined('SYSTEM_INSTALLATION')) {
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.5';
$new_file_version = '1.8.6';
@ -82,18 +83,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
}
}
@ -106,15 +107,15 @@ if (defined('SYSTEM_INSTALLATION')) {
// Filling the access_url_rel_user table with access_url_id by default = 1
$query = "SELECT user_id FROM $dbNameForm.user";
$result_users = Database::query($query);
while ($row = Database::fetch_array($result_users, 'NUM')) {
$result_users = iDatabase::query($query);
while ($row = iDatabase::fetch_array($result_users, 'NUM')) {
$user_id = $row[0];
$sql = "INSERT INTO $dbNameForm.access_url_rel_user SET user_id=$user_id, access_url_id=1";
$res = Database::query($sql);
$res = iDatabase::query($sql);
//Updating user image
$query = "SELECT picture_uri FROM $dbNameForm.user WHERE user_id=$user_id";
$res = Database::query($query);
$picture_uri = Database::fetch_array($res, 'NUM');
$res = iDatabase::query($query);
$picture_uri = iDatabase::fetch_array($res, 'NUM');
$file = $picture_uri[0];
$dir = api_get_path(SYS_CODE_PATH).'upload/users/';
$image_repository = file_exists($dir.$file) ? $dir.$file : $dir.$user_id.'/'.$file;
@ -123,7 +124,7 @@ if (defined('SYSTEM_INSTALLATION')) {
@mkdir($dir.$user_id, $perm);
}
if (file_exists($image_repository)) {
if (file_exists($image_repository) && is_file($image_repository)) {
chmod($dir.$user_id, 0777);
if (is_dir($dir.$user_id)) {
$picture_location = $dir.$user_id.'/'.$file;
@ -166,10 +167,10 @@ if (defined('SYSTEM_INSTALLATION')) {
}
// Filling the access_url_rel_session table with access_url_id by default = 1
$query = "SELECT id FROM $dbNameForm.session";
$result = Database::query($query);
while ($row = Database::fetch_array($result, 'NUM')) {
$result = iDatabase::query($query);
while ($row = iDatabase::fetch_array($result, 'NUM')) {
$sql = "INSERT INTO $dbNameForm.access_url_rel_session SET session_id=".$row[0].", access_url_id=1";
$res = Database::query($sql);
$res = iDatabase::query($sql);
}
// Since the parser of the migration DB does not work for this kind of inserts (HTML) we move it here
@ -208,7 +209,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
/*
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -258,7 +259,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
*/
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -298,7 +299,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');
';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleLeftList\', \'TemplateTitleListLeftListDescription\', \'leftlist.gif\', \'
@ -336,7 +337,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleLeftRightList\', \'TemplateTitleLeftRightListDescription\', \'leftrightlist.gif\', \'
@ -388,7 +389,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleRightList\', \'TemplateTitleRightListDescription\', \'rightlist.gif\', \'
@ -427,7 +428,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
/*
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -454,7 +455,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</tr>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
*/
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -490,7 +491,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');
';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleDesc\', \'TemplateTitleCheckListDescription\', \'description.gif\', \'
@ -519,7 +520,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');
';
$res = Database::query($sql);
$res = iDatabase::query($sql);
/*
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -560,7 +561,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
*/
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -626,7 +627,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
/*
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -669,7 +670,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');
';
$res = Database::query($sql);
$res = iDatabase::query($sql);
*/
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -736,7 +737,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</body>
\');
';
$res = Database::query($sql);
$res = iDatabase::query($sql);
/*
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -770,7 +771,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
*/
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
@ -837,7 +838,7 @@ if (defined('SYSTEM_INSTALLATION')) {
<br />
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleAudio\', \'TemplateTitleAudioDescription\', \'audiocomment.gif\', \'
@ -872,7 +873,7 @@ if (defined('SYSTEM_INSTALLATION')) {
</p>
</body>
\');';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleVideo\', \'TemplateTitleVideoDescription\', \'video.gif\', \'
@ -934,7 +935,7 @@ if (defined('SYSTEM_INSTALLATION')) {
<style type="text/css">body{}</style><!-- to fix a strange bug appearing with firefox when editing this template -->
</body>
\'); ';
$res = Database::query($sql);
$res = iDatabase::query($sql);
$sql = 'INSERT INTO '.$dbNameForm.'.system_template (title, comment, image, content) VALUES
(\'TemplateTitleFlash\', \'TemplateTitleFlashDescription\', \'flash.gif\', \'
@ -958,11 +959,11 @@ if (defined('SYSTEM_INSTALLATION')) {
</center>
</body>
\'); ';
$res = Database::query($sql);
$res = iDatabase::query($sql);
// Check if course_module exists, as it was not installed in Dokeos 1.8.5 because of a broken query, and $sql = 'INSERT it if necessary
$query = "SELECT * FROM $dbNameForm.course_module";
$result = Database::query($query);
$result = iDatabase::query($query);
if ($result === false) {
//the course_module table doesn't exist, create it
$sql = "CREATE TABLE $dbNameForm.course_module (
@ -976,7 +977,7 @@ if (defined('SYSTEM_INSTALLATION')) {
PRIMARY KEY (id)
)
";
$result = Database::query($sql);
$result = iDatabase::query($sql);
if ($result !== false) {
$sql = "INSERT INTO $dbNameForm.course_module (name, link, image, `row`,`column`, position) VALUES
('calendar_event','calendar/agenda.php','agenda.gif',1,1,'basic'),
@ -1007,7 +1008,7 @@ if (defined('SYSTEM_INSTALLATION')) {
('gradebook','gradebook/index.php','gradebook.gif',2,2,'basic'),
('glossary','glossary/index.php','glossary.gif',2,1,'basic'),
('notebook','notebook/index.php','notebook.gif',2,1,'basic')";
$res = Database::query($sql);
$res = iDatabase::query($sql);
}
}
@ -1021,18 +1022,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
Log::error('Database name '.$dbStatsForm.' is too long, skipping');
} elseif (!in_array($dbStatsForm,$dblist)) {
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database '.$dbStatsForm.' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("iDatabase::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
Log::notice("In $dbStatsForm, executed: $query");
}
}
}
@ -1047,17 +1048,17 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
Log::error('Database name '.$dbUserForm.' is too long, skipping');
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database '.$dbUserForm.' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
error_log("iDatabase::query($dbUserForm,$query)");
error_log("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
}
}
}
@ -1076,19 +1077,19 @@ if (defined('SYSTEM_INSTALLATION')) {
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
error_log('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
error_log('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.5-1.8.6.inc.php'); }
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -1099,8 +1100,9 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) { //otherwise just use the main one
@ -1108,11 +1110,11 @@ if (defined('SYSTEM_INSTALLATION')) {
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::notice("iDatabase::query(".$row_course['db_name'].",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
Log::notice("In ".$row_course['db_name'].", executed: $query");
}
}
}
@ -1126,11 +1128,11 @@ if (defined('SYSTEM_INSTALLATION')) {
}
// Shared documents folder
$query = "INSERT INTO $t_d (path,title,filetype,size) VALUES ('/shared_folder','".get_lang('SharedDocumentsDirectory')."','folder','0')";
$myres = Database::query($query);
$myres = iDatabase::query($query);
if ($myres !== false) {
$doc_id = Database::insert_id();
$doc_id = iDatabase::insert_id();
$query = "INSERT INTO $t_ip (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$doc_id,'FolderAdded',1,0,NULL,1)";
$myres = Database::query($query);
$myres = iDatabase::query($query);
}
}
}

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.6';
$new_file_version = '1.8.6.1';
@ -82,18 +83,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach($m_q_list as $query) {
if ($only_test){
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
}
}
@ -111,18 +112,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
Log::error('Database name '.$dbStatsForm.' is too long, skipping');
} elseif (!in_array($dbStatsForm,$dblist)) {
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database '.$dbStatsForm.' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("iDatabase::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
Log::notice("In $dbStatsForm, executed: $query");
}
}
}
@ -137,17 +138,17 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
Log::error('Database name '.$dbUserForm.' is too long, skipping');
} elseif (!in_array($dbUserForm, $dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database '.$dbUserForm.' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
Log::notice("iDatabase::query($dbUserForm,$query)");
Log::notice("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
}
}
}
@ -166,19 +167,19 @@ if (defined('SYSTEM_INSTALLATION')) {
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6-1.8.6.1.inc.php'); }
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -189,8 +190,9 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {
@ -198,11 +200,11 @@ if (defined('SYSTEM_INSTALLATION')) {
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::notice("iDatabase::query(".$row_course['db_name'].",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
Log::notice("In ".$row_course['db_name'].", executed: $query");
}
}
}
@ -217,11 +219,11 @@ if (defined('SYSTEM_INSTALLATION')) {
// Update correct page_id to wiki table, actually only store 0
$query = "SELECT id, reflink FROM $t_wiki";
$res_page = Database::query($query);
$res_page = iDatabase::query($query);
$wiki_id = $reflink = array();
if (Database::num_rows($res_page) > 0) {
while ($row_page = Database::fetch_row($res_page)) {
if (iDatabase::num_rows($res_page) > 0) {
while ($row_page = iDatabase::fetch_row($res_page)) {
$wiki_id[] = $row_page[0];
$reflink[] = $row_page[1];
}
@ -234,19 +236,19 @@ if (defined('SYSTEM_INSTALLATION')) {
foreach ($wiki_id as $key => $wiki_page) {
$pag_id = $reflink_flip[$reflink[$key]];
$sql= "UPDATE $t_wiki SET page_id='".($pag_id + 1)."' WHERE id = '$wiki_page'";
$res_update = Database::query($sql);
$res_update = iDatabase::query($sql);
}
}
// Insert page_id into wiki_conf table, actually this table is empty
$query = "SELECT DISTINCT page_id FROM $t_wiki ORDER BY page_id";
$myres_wiki = Database::query($query);
$myres_wiki = iDatabase::query($query);
if (Database::num_rows($myres_wiki) > 0) {
while ($row_wiki = Database::fetch_row($myres_wiki)) {
if (iDatabase::num_rows($myres_wiki) > 0) {
while ($row_wiki = iDatabase::fetch_row($myres_wiki)) {
$page_id = $row_wiki[0];
$query = "INSERT INTO ".$t_wiki_conf." (page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3) VALUES ('".$page_id."','','','','','','','')";
$myres_wiki_conf = Database::query($query);
$myres_wiki_conf = iDatabase::query($query);
}
}

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.6.1';
$new_file_version = '1.8.6.2';
@ -82,18 +83,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
}
}
@ -109,21 +110,21 @@ if (defined('SYSTEM_INSTALLATION')) {
FROM session_rel_course
ORDER BY id_session, course_code";
$res = Database::query($sql);
$res = iDatabase::query($sql);
if ($res === false) {
error_log('Could not query session course coaches table: '.Database::error());
Log::error('Could not query session course coaches table: '.iDatabase::error());
} else {
// For each coach found, add him as a course coach in the
// session_rel_course_rel_user table
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
// Check whether coach is a student
$sql = "SELECT 1 FROM session_rel_course_rel_user
WHERE id_session='{$row[id_session]}' AND course_code='{$row[course_code]}' AND id_user='{$row[id_coach]}'";
$rs = Database::query($sql);
$rs = iDatabase::query($sql);
if (Database::num_rows($rs) > 0) {
if (iDatabase::num_rows($rs) > 0) {
$sql_upd = "UPDATE session_rel_course_rel_user SET status=2
WHERE id_session='{$row[id_session]}' AND course_code='{$row[course_code]}' AND id_user='{$row[id_coach]}'";
} else {
@ -131,10 +132,10 @@ if (defined('SYSTEM_INSTALLATION')) {
VALUES ('{$row[id_session]}','{$row[course_code]}','{$row[id_coach]}',2)";
}
$rs_coachs = Database::query($sql_ins);
$rs_coachs = iDatabase::query($sql_ins);
if ($rs_coachs === false) {
error_log('Could not move course coach to new table: '.Database::error());
Log::error('Could not move course coach to new table: '.iDatabase::error());
}
}
@ -143,34 +144,34 @@ if (defined('SYSTEM_INSTALLATION')) {
// Remove duplicated rows for 'show_tutor_data' AND 'show_teacher_data' into settings_current table
$sql = "SELECT id FROM settings_current WHERE variable='show_tutor_data' ORDER BY id";
$rs_chk_id1 = Database::query($sql);
$rs_chk_id1 = iDatabase::query($sql);
if ($rs_chk_id1 === false) {
error_log('Could not query settings_current ids table: '.Database::error());
Log::error('Could not query settings_current ids table: '.iDatabase::error());
} else {
$i = 1;
while ($row_id1 = Database::fetch_array($rs_chk_id1)) {
while ($row_id1 = iDatabase::fetch_array($rs_chk_id1)) {
$id = $row_id1['id'];
if ($i > 1) {
$sql_del = "DELETE FROM settings_current WHERE id = '$id'";
Database::query($sql_del);
iDatabase::query($sql_del);
}
$i++;
}
}
$sql = "SELECT id FROM settings_current WHERE variable='show_teacher_data' ORDER BY id";
$rs_chk_id2 = Database::query($sql);
$rs_chk_id2 = iDatabase::query($sql);
if ($rs_chk_id2 === false) {
error_log('Could not query settings_current ids table: '.Database::error());
Log::error('Could not query settings_current ids table: '.iDatabase::error());
} else {
$i = 1;
while ($row_id2 = Database::fetch_array($rs_chk_id2)) {
while ($row_id2 = iDatabase::fetch_array($rs_chk_id2)) {
$id = $row_id2['id'];
if ($i > 1) {
$sql_del = "DELETE FROM settings_current WHERE id = '$id'";
Database::query($sql_del);
iDatabase::query($sql_del);
}
$i++;
}
@ -187,18 +188,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
}
}
@ -215,18 +216,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
Log::error('Database name '.$dbStatsForm.' is too long, skipping');
} elseif (!in_array($dbStatsForm, $dblist)) {
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database '.$dbStatsForm.' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("iDatabase::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
Log::notice("In $dbStatsForm, executed: $query");
}
}
}
@ -241,17 +242,17 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
Log::error('Database name '.$dbUserForm.' is too long, skipping');
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database '.$dbUserForm.' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test){
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
Log::notice("iDatabase::query($dbUserForm,$query)");
Log::notice("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
}
}
}
@ -270,19 +271,19 @@ if (defined('SYSTEM_INSTALLATION')) {
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.1-1.8.6.2.inc.php'); }
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -293,8 +294,9 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (!$singleDbForm) { //otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {
@ -302,11 +304,11 @@ if (defined('SYSTEM_INSTALLATION')) {
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::error("iDatabase::query(".$row_course['db_name'].",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
Log::error("In ".$row_course['db_name'].", executed: $query");
}
}
}
@ -321,16 +323,16 @@ if (defined('SYSTEM_INSTALLATION')) {
// Get all ids and update description_type field with them from course_description table
$sql_sel = "SELECT id FROM $t_course_description";
$rs_sel = Database::query($sql_sel);
$rs_sel = iDatabase::query($sql_sel);
if ($rs_sel === false) {
error_log('Could not query course_description ids table: '.Database::error());
Log::error('Could not query course_description ids table: '.iDatabase::error());
} else {
if (Database::num_rows($rs_sel) > 0) {
while ($row_ids = Database::fetch_array($rs_sel)) {
if (iDatabase::num_rows($rs_sel) > 0) {
while ($row_ids = iDatabase::fetch_array($rs_sel)) {
$description_id = $row_ids['id'];
$sql_upd = "UPDATE $t_course_description SET description_type='$description_id' WHERE id='$description_id'";
Database::query($sql_upd);
iDatabase::query($sql_upd);
}
}
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -16,6 +17,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.6.2';
$new_file_version = '1.8.7';
@ -25,11 +27,11 @@ if (defined('SYSTEM_INSTALLATION')) {
// Check if the current Chamilo install is eligible for update
if (!file_exists('../inc/conf/configuration.php')) {
echo '<strong>'.get_lang('Error').' !</strong> Chamilo '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br /><br />
'.get_lang('PleasGoBackToStep1').'.
<p><button type="submit" class="back" name="step1" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>
echo '<strong>' . get_lang('Error') . ' !</strong> Chamilo ' . implode('|', $updateFromVersion) . ' ' . get_lang('HasNotBeenFound') . '.<br /><br />
' . get_lang('PleasGoBackToStep1') . '.
<p><button type="submit" class="back" name="step1" value="&lt; ' . get_lang('Back') . '">' . get_lang('Back') . '</button></p>
</td></tr></table></form></body></html>';
exit ();
exit();
}
$_configuration['db_glue'] = get_config_param('dbGlu');
@ -40,14 +42,14 @@ if (defined('SYSTEM_INSTALLATION')) {
$_configuration['db_prefix'] = get_config_param('dbNamePrefix');
}
$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
$dbScormForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbScormForm);
if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
$dbScormForm = $dbPrefixForm.$dbScormForm;
if (!empty($dbPrefixForm) && strpos($dbScormForm, $dbPrefixForm) !== 0) {
$dbScormForm = $dbPrefixForm . $dbScormForm;
}
if (empty($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm) {
$dbScormForm = $dbPrefixForm.'scorm';
$dbScormForm = $dbPrefixForm . 'scorm';
}
/* Normal upgrade procedure: start by updating main, statistic, user databases */
@ -70,11 +72,11 @@ if (defined('SYSTEM_INSTALLATION')) {
if ($languageForm != 'english') {
// languageForm has been escaped in index.php
include '../lang/'.$languageForm.'/create_course.inc.php';
include '../lang/' . $languageForm . '/create_course.inc.php';
}
// Get the main queries list (m_q_list)
$m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'main');
$m_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'main');
if (count($m_q_list) > 0) {
// Now use the $m_q_list
/**
@ -82,36 +84,36 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
Database::select_db($dbNameForm);
foreach ($m_q_list as $query){
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("Database::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
$tables = Database::get_tables($dbNameForm);
$tables = iDatabase::get_tables($dbNameForm);
foreach ($tables as $table) {
$query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
$query = "ALTER DATABASE `".$dbNameForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$query = "ALTER DATABASE `" . $dbNameForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = Database::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
@ -126,94 +128,93 @@ if (defined('SYSTEM_INSTALLATION')) {
$timeOffsetSeconds = $dateTimeZoneCurrent->getOffset($dateTimeUTC);
$timeOffsetHours = $timeOffsetSeconds / 3600;
$timeOffsetString = "";
if($timeOffsetHours < 0) {
$timeOffsetString .= "-";
$timeOffsetHours = abs($timeOffsetHours);
if ($timeOffsetHours < 0) {
$timeOffsetString .= "-";
$timeOffsetHours = abs($timeOffsetHours);
} else {
$timeOffsetString .= "+";
$timeOffsetString .= "+";
}
if($timeOffsetHours < 10) {
$timeOffsetString .= "0";
if ($timeOffsetHours < 10) {
$timeOffsetString .= "0";
}
$timeOffsetString .= "$timeOffsetHours";
$timeOffsetString .= ":00";
// Executing the queries to convert everything
$queries[] = "UPDATE gradebook_certificate SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_evaluation SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_link SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_linkeval_log SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_result SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_result_log SET created_at = CONVERT_TZ(created_at, '".$timeOffsetString."', '+00:00');";
$queries[] = "UPDATE gradebook_certificate SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
$queries[] = "UPDATE gradebook_evaluation SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
$queries[] = "UPDATE gradebook_link SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
$queries[] = "UPDATE gradebook_linkeval_log SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
$queries[] = "UPDATE gradebook_result SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
$queries[] = "UPDATE gradebook_result_log SET created_at = CONVERT_TZ(created_at, '" . $timeOffsetString . "', '+00:00');";
foreach ($queries as $query) {
Database::query($query);
iDatabase::query($query);
}
}
// Moving user followed by a human resource manager from hr_dept_id field to user_rel_user table
$query = "SELECT user_id, hr_dept_id FROM $dbNameForm.user";
$result = Database::query($query);
if (Database::num_rows($result) > 0) {
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
while ($row = Database::fetch_array($result, 'ASSOC')) {
$result = iDatabase::query($query);
if (iDatabase::num_rows($result) > 0) {
require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
while ($row = iDatabase::fetch_array($result, 'ASSOC')) {
$user_id = $row['user_id'];
$hr_dept_id = $row['hr_dept_id'];
// moving data to user_rel_user table
if (!empty($hr_dept_id)) {
$sql = " SELECT id FROM $dbNameForm.user_rel_user WHERE user_id = $user_id AND friend_user_id = $hr_dept_id AND relation_type = ".USER_RELATION_TYPE_RRHH." ";
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$ins = "INSERT INTO $dbNameForm.user_rel_user SET user_id = $user_id, friend_user_id = $hr_dept_id, relation_type = ".USER_RELATION_TYPE_RRHH." ";
Database::query($ins);
$sql = " SELECT id FROM $dbNameForm.user_rel_user WHERE user_id = $user_id AND friend_user_id = $hr_dept_id AND relation_type = " . USER_RELATION_TYPE_RRHH . " ";
$rs = iDatabase::query($sql);
if (iDatabase::num_rows($rs) == 0) {
$ins = "INSERT INTO $dbNameForm.user_rel_user SET user_id = $user_id, friend_user_id = $hr_dept_id, relation_type = " . USER_RELATION_TYPE_RRHH . " ";
iDatabase::query($ins);
}
}
}
// cleaning hr_dept_id field inside user table
$upd = "UPDATE $dbNameForm.user SET hr_dept_id = 0";
Database::query($upd);
iDatabase::query($upd);
}
// Updating score display for each gradebook category
// first we check if there already is migrated data to categoy_id field
$query = "SELECT id FROM $dbNameForm.gradebook_score_display WHERE category_id = 0";
$rs_check = Database::query($query);
$rs_check = iDatabase::query($query);
if (Database::num_rows($rs_check) > 0) {
if (iDatabase::num_rows($rs_check) > 0) {
// get all gradebook categories id
$a_categories = array();
$query = "SELECT id FROM $dbNameForm.gradebook_category";
$rs_gradebook = Database::query($query);
if (Database::num_rows($rs_gradebook) > 0) {
while($row_gradebook = Database::fetch_row($rs_gradebook)) {
$rs_gradebook = iDatabase::query($query);
if (iDatabase::num_rows($rs_gradebook) > 0) {
while ($row_gradebook = iDatabase::fetch_row($rs_gradebook)) {
$a_categories[] = $row_gradebook[0];
}
}
// get all gradebook score display
$query = "SELECT * FROM $dbNameForm.gradebook_score_display";
$rs_score_display = Database::query($query);
if (Database::num_rows($rs_score_display) > 0) {
$rs_score_display = iDatabase::query($query);
if (iDatabase::num_rows($rs_score_display) > 0) {
$score_color_percent = api_get_setting('gradebook_score_display_colorsplit');
while ($row_score_display = Database::fetch_array($rs_score_display)) {
while ($row_score_display = iDatabase::fetch_array($rs_score_display)) {
$score = $row_score_display['score'];
$display = $row_score_display['display'];
foreach ($a_categories as $category_id) {
$ins = "INSERT INTO $dbNameForm.gradebook_score_display(score, display, category_id, score_color_percent) VALUES('$score', '$display', $category_id, '$score_color_percent')";
Database::query($ins);
iDatabase::query($ins);
}
}
// remove score display with category id = 0
$del = "DELETE FROM $dbNameForm.gradebook_score_display WHERE category_id = 0";
Database::query($del);
iDatabase::query($del);
}
}
// Now clean the deprecated id_coach field from the session_rel_course table
$m_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'main');
$m_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-post.sql', 'main');
if (count($m_q_list) > 0) {
// Now use the $m_q_list
/**
@ -221,18 +222,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("Database::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
}
}
@ -240,7 +241,7 @@ if (defined('SYSTEM_INSTALLATION')) {
}
// Get the stats queries list (s_q_list)
$s_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'stats');
$s_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'stats');
if (count($s_q_list) > 0) {
// Now use the $s_q_list
/**
@ -248,82 +249,80 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
} elseif (!in_array($dbStatsForm, $dblist)){
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database name ' . $dbStatsForm . ' is too long, skipping');
} elseif (!in_array($dbStatsForm, $dblist)) {
Log::error('Database ' . $dbStatsForm . ' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("Database::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
Log::notice("In $dbStatsForm, executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
$tables = Database::get_tables($dbStatsForm);
$tables = iDatabase::get_tables($dbStatsForm);
foreach ($tables as $table) {
$query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
$query = "ALTER DATABASE `".$dbStatsForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER DATABASE `" . $dbStatsForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
// chamilo_stat.track_e_attempt table update changing id by id_auto
$sql = "SELECT exe_id, question_id, course_code, answer FROM $dbStatsForm.track_e_attempt";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$course_code = $row['course_code'];
$course_info = api_get_course_info($course_code);
$my_course_db = $course_info['dbName'];
$question_id = $row['question_id'];
$answer = $row['answer'];
$exe_id = $row['exe_id'];
//getting the type question id
$sql_question = "SELECT type FROM $my_course_db.quiz_question where id = $question_id";
$res_question = Database::query($sql_question);
$row = Database::fetch_array($res_question);
$type = $row['type'];
require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
//this type of questions produce problems in the track_e_attempt table
if (in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MATCHING, MULTIPLE_ANSWER_COMBINATION))) {
$sql_question = "SELECT id_auto FROM $my_course_db.quiz_answer where question_id = $question_id and id = $answer";
$res_question = Database::query($sql_question);
$row = Database::fetch_array($res_question);
$id_auto = $row['id_auto'];
if (!empty($id_auto)) {
$sql = "UPDATE $dbStatsForm.track_e_attempt SET answer = '$id_auto' WHERE exe_id = $exe_id AND question_id = $question_id AND course_code = '$course_code' and answer = $answer ";
Database::query($sql);
}
}
}
$sql = "SELECT exe_id, question_id, course_code, answer FROM $dbStatsForm.track_e_attempt";
$result = iDatabase::query($sql);
if (iDatabase::num_rows($result) > 0) {
while ($row = iDatabase::fetch_array($result)) {
$course_code = $row['course_code'];
$course_info = api_get_course_info($course_code);
$my_course_db = $course_info['dbName'];
$question_id = $row['question_id'];
$answer = $row['answer'];
$exe_id = $row['exe_id'];
//getting the type question id
$sql_question = "SELECT type FROM $my_course_db.quiz_question where id = $question_id";
$res_question = iDatabase::query($sql_question);
$row = iDatabase::fetch_array($res_question);
$type = $row['type'];
require_once api_get_path(SYS_CODE_PATH) . 'exercice/question.class.php';
//this type of questions produce problems in the track_e_attempt table
if (in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER, MATCHING, MULTIPLE_ANSWER_COMBINATION))) {
$sql_question = "SELECT id_auto FROM $my_course_db.quiz_answer where question_id = $question_id and id = $answer";
$res_question = iDatabase::query($sql_question);
$row = iDatabase::fetch_array($res_question);
$id_auto = $row['id_auto'];
if (!empty($id_auto)) {
$sql = "UPDATE $dbStatsForm.track_e_attempt SET answer = '$id_auto' WHERE exe_id = $exe_id AND question_id = $question_id AND course_code = '$course_code' and answer = $answer ";
iDatabase::query($sql);
}
}
}
}
}
}
// Get the user queries list (u_q_list)
$u_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'user');
$u_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'user');
if (count($u_q_list) > 0) {
// Now use the $u_q_list
/**
@ -331,34 +330,34 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database name ' . $dbUserForm . ' is too long, skipping');
} elseif (!in_array($dbUserForm, $dblist)) {
Log::error('Database ' . $dbUserForm . ' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
Log::notice("Database::query($dbUserForm,$query)");
Log::notice("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
$tables = Database::get_tables($dbUserForm);
$tables = iDatabase::get_tables($dbUserForm);
foreach ($tables as $table) {
$query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
$query = "ALTER DATABASE `".$dbUserForm."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER DATABASE `" . $dbUserForm . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
@ -367,27 +366,29 @@ if (defined('SYSTEM_INSTALLATION')) {
$prefix = '';
if ($singleDbForm) {
$prefix = get_config_param ('table_prefix');
$prefix = get_config_param('table_prefix');
}
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'course');
$c_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-pre.sql', 'course');
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
} elseif(!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
if ($res === false) {
die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php');
}
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -398,7 +399,7 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (!$singleDbForm) { // otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
foreach ($c_q_list as $query) {
@ -407,35 +408,35 @@ if (defined('SYSTEM_INSTALLATION')) {
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::notice("Database::query(" . $row_course['db_name'] . ",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
Log::notice("In " . $row_course['db_name'] . ", executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
if (!$singleDbForm) {
$tables = Database::get_tables($row_course['db_name']);
$tables = iDatabase::get_tables($row_course['db_name']);
foreach ($tables as $table) {
$query = "ALTER TABLE `".$table."` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER TABLE `" . $table . "` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
$query = "ALTER DATABASE `".$row_course['db_name']."` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = Database::query($query);
$query = "ALTER DATABASE `" . $row_course['db_name'] . "` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
$t_student_publication = $row_course['db_name'].".student_publication";
$t_item_property = $row_course['db_name'].".item_property";
$t_student_publication = $row_course['db_name'] . ".student_publication";
$t_item_property = $row_course['db_name'] . ".item_property";
if ($singleDbForm) {
$t_student_publication = "$prefix{$row_course['db_name']}_student_publication";
@ -444,85 +445,81 @@ if (defined('SYSTEM_INSTALLATION')) {
$sql_insert_user = "SELECT ref, insert_user_id FROM $t_item_property WHERE tool='work'";
$rs_insert_user = Database::query($sql_insert_user);
$rs_insert_user = iDatabase::query($sql_insert_user);
if ($rs_insert_user === false) {
error_log('Could not query insert_user_id table: '.Database::error());
} else {
if (Database::num_rows($rs_insert_user) > 0) {
while ($row_ids = Database::fetch_array($rs_insert_user)) {
$user_id = $row_ids['insert_user_id'];
$ref = $row_ids['ref'];
$sql_upd = "UPDATE $t_student_publication SET user_id='$user_id' WHERE id='$ref'";
Database::query($sql_upd);
}
}
}
//updating parent_id of the student_publication table
$sql = 'SELECT id, url, parent_id FROM '.$t_student_publication;
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$items = Database::store_result($result);
$directory_list = $file_list=array();
foreach($items as $item) {
$student_slash = substr($item['url'], 0, 1);
//means this is a directory
if ($student_slash == '/') {
$directory_list[$item['id']]= $item['url'];
} else {
// this is a file with no parents
if ($item['parent_id'] == 0)
$file_list []= $item;
}
}
if (is_array($file_list) && count($file_list) > 0) {
foreach ($file_list as $file) {
$parent_id = 0;
if (is_array($directory_list) && count($directory_list) > 0) {
foreach($directory_list as $id => $dir) {
$pos = strpos($file['url'], $dir.'/');
if ($pos !== false) {
$parent_id = $id;
break;
}
}
}
if ($parent_id != 0 ) {
$sql = 'UPDATE '.$t_student_publication.' SET parent_id = '.$parent_id.' WHERE id = '.$file['id'].'';
Database::query($sql);
}
}
}
}
Log::error('Could not query insert_user_id table: ' . iDatabase::error());
} else {
if (iDatabase::num_rows($rs_insert_user) > 0) {
while ($row_ids = iDatabase::fetch_array($rs_insert_user)) {
$user_id = $row_ids['insert_user_id'];
$ref = $row_ids['ref'];
$sql_upd = "UPDATE $t_student_publication SET user_id='$user_id' WHERE id='$ref'";
iDatabase::query($sql_upd);
}
}
}
//updating parent_id of the student_publication table
$sql = 'SELECT id, url, parent_id FROM ' . $t_student_publication;
$result = iDatabase::query($sql);
if (iDatabase::num_rows($result) > 0) {
$items = iDatabase::store_result($result);
$directory_list = $file_list = array();
foreach ($items as $item) {
$student_slash = substr($item['url'], 0, 1);
//means this is a directory
if ($student_slash == '/') {
$directory_list[$item['id']] = $item['url'];
} else {
// this is a file with no parents
if ($item['parent_id'] == 0)
$file_list [] = $item;
}
}
if (is_array($file_list) && count($file_list) > 0) {
foreach ($file_list as $file) {
$parent_id = 0;
if (is_array($directory_list) && count($directory_list) > 0) {
foreach ($directory_list as $id => $dir) {
$pos = strpos($file['url'], $dir . '/');
if ($pos !== false) {
$parent_id = $id;
break;
}
}
}
if ($parent_id != 0) {
$sql = 'UPDATE ' . $t_student_publication . ' SET parent_id = ' . $parent_id . ' WHERE id = ' . $file['id'] . '';
iDatabase::query($sql);
}
}
}
}
}
}
}
}
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-post.sql', 'course');
$c_q_list = get_sql_file_contents('migrate-db-' . $old_file_version . '-' . $new_file_version . '-post.sql', 'course');
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
if (Database::num_rows($res) > 0) {
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) {
die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php');
}
if (iDatabase::num_rows($res) > 0) {
$i = 0;
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -534,21 +531,21 @@ if (defined('SYSTEM_INSTALLATION')) {
*/
$prefix_course = $prefix;
if ($singleDbForm) {
$prefix_course = $prefix.$row['db_name']."_";
$prefix_course = $prefix . $row['db_name'] . "_";
} else {
Database::select_db($row['db_name']);
iDatabase::select_db($row['db_name']);
}
foreach($c_q_list as $query) {
foreach ($c_q_list as $query) {
if ($singleDbForm) { //otherwise just use the main one
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
}
if ($only_test) {
error_log("Database::query(".$row['db_name'].",$query)", 0);
Log::notice("Database::query(" . $row['db_name'] . ",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row['db_name'].", executed: $query", 0);
Log::notice("In " . $row['db_name'] . ", executed: $query");
}
}
}
@ -556,10 +553,7 @@ if (defined('SYSTEM_INSTALLATION')) {
}
}
}
} else {
echo 'You are not allowed here !';
}

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.7';
$new_file_version = '1.8.8';
@ -82,21 +83,21 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query){
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
Log::notice("In $dbNameForm, executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -111,18 +112,18 @@ if (defined('SYSTEM_INSTALLATION')) {
// We connect to the right DB first to make sure we can use the queries
// without a database name.
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
error_log('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm,$dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
error_log('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
error_log("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
error_log("In $dbNameForm, executed: $query");
}
}
}
@ -139,22 +140,22 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
Log::error('Database name '.$dbStatsForm.' is too long, skipping');
} elseif (!in_array($dbStatsForm, $dblist)){
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database '.$dbStatsForm.' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("iDatabase::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
Log::notice("In $dbStatsForm, executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -172,19 +173,19 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
Log::error('Database name '.$dbUserForm.' is too long, skipping');
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database '.$dbUserForm.' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
Log::notice("iDatabase::query($dbUserForm,$query)");
Log::notice("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -203,19 +204,19 @@ if (defined('SYSTEM_INSTALLATION')) {
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif(!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -226,8 +227,9 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (!$singleDbForm) { // otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {
@ -235,14 +237,14 @@ if (defined('SYSTEM_INSTALLATION')) {
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::notice("iDatabase::query(".$row_course['db_name'].",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
Log::notice("In ".$row_course['db_name'].", executed: $query");
}
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -262,35 +264,35 @@ if (defined('SYSTEM_INSTALLATION')) {
$query = "SELECT DISTINCT path as exercise_id, lp_item_id, lp_view_id, user_id, v.lp_id
FROM $table_lp_item_view iv INNER JOIN $table_lp_view v ON v.id = iv.lp_view_id INNER JOIN $table_lp_item i ON i.id = lp_item_id
WHERE item_type = 'quiz'";
$result = Database::query($query);
$result = iDatabase::query($query);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result,'ASSOC')) {
if (iDatabase::num_rows($result) > 0) {
while ($row = iDatabase::fetch_array($result,'ASSOC')) {
$sql = "SELECT exe_id FROM $dbNameForm.track_e_exercices
WHERE exe_user_id = {$row['user_id']} AND
exe_cours_id = '{$row_course['code']}' AND
exe_exo_id = {$row['exercise_id']} AND
orig_lp_id = {$row['lp_id']} AND
orig_lp_item_id = {$row['lp_item_id']} ";
$sub_result = Database::query($sql);
$sub_result = iDatabase::query($sql);
$exe_list = array();
while ($sub_row = Database::fetch_array($sub_result,'ASSOC')) {
while ($sub_row = iDatabase::fetch_array($sub_result,'ASSOC')) {
$exe_list[] = $sub_row['exe_id'];
}
$sql = "SELECT iv.id, iv.view_count
FROM $table_lp_item_view iv INNER JOIN $table_lp_view v ON v.id = iv.lp_view_id INNER JOIN $table_lp_item i ON i.id = lp_item_id
WHERE item_type = 'quiz' AND user_id = {$row['user_id']} AND path = {$row['exercise_id']} ";
$sub_result = Database::query($sql);
$sub_result = iDatabase::query($sql);
$lp_item_view_id_list = array();
while ($sub_row = Database::fetch_array($sub_result,'ASSOC')) {
while ($sub_row = iDatabase::fetch_array($sub_result,'ASSOC')) {
$lp_item_view_id_list[] = $sub_row['id'];
}
$i = 0;
foreach($exe_list as $exe_id) {
$lp_item_view_id = $lp_item_view_id_list[$i];
$update = "UPDATE $dbNameForm.track_e_exercices SET orig_lp_item_view_id = '$lp_item_view_id' WHERE exe_id = $exe_id ";
Database::query($update);
iDatabase::query($update);
$i++;
}
}
@ -301,49 +303,49 @@ if (defined('SYSTEM_INSTALLATION')) {
//Adding notifications options
$sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_invitation', 'MailNotifyInvitation',1,1,'1') ";
$result = Database::query($sql);
$id = Database::insert_id();
$result = iDatabase::query($sql);
$id = iDatabase::insert_id();
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_message', 'MailNotifyMessage',1,1,'1')";
$result = Database::query($sql);
$id = Database::insert_id();
$result = iDatabase::query($sql);
$id = iDatabase::insert_id();
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_group_message','MailNotifyGroupMessage',1,1,'1') ";
$result = Database::query($sql);
$id = Database::insert_id();
$result = iDatabase::query($sql);
$id = iDatabase::insert_id();
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '1', 'AtOnce',1) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '8', 'Daily',2) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$sql = "INSERT INTO $dbNameForm.user_field_options (field_id, option_value, option_display_text, option_order) values ($id, '0', 'No',3) ";
$result = Database::query($sql);
$result = iDatabase::query($sql);
//Fixing table access_url_rel_course if the platform have courses that were created in Dok€os 1.8.5
if (!isset($_configuration['multiple_access_urls']) || $_configuration['multiple_access_urls'] == false) {
$sql = "SELECT code FROM $dbNameForm.course";
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
$result = iDatabase::query($sql);
while ($row = iDatabase::fetch_array($result)) {
//Adding course to default URL just in case
$sql = "INSERT INTO $dbNameForm.access_url_rel_course SET course_code = '".Database::escape_string($row['code'])."', access_url_id = '1' ";
Database::query($sql);
$sql = "INSERT INTO $dbNameForm.access_url_rel_course SET course_code = '".iDatabase::escape_string($row['code'])."', access_url_id = '1' ";
iDatabase::query($sql);
}
}
}
@ -360,16 +362,16 @@ if (defined('SYSTEM_INSTALLATION')) {
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.7-1.8.8.inc.php'); }
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -381,7 +383,7 @@ if (defined('SYSTEM_INSTALLATION')) {
if ($singleDbForm) {
$prefix_course = $prefix.$row['db_name']."_";
} else {
Database::select_db($row['db_name']);
iDatabase::select_db($row['db_name']);
}
foreach($c_q_list as $query) {
@ -389,11 +391,11 @@ if (defined('SYSTEM_INSTALLATION')) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix$2$3", $query);
}
if ($only_test) {
error_log("Database::query(".$row['db_name'].",$query)", 0);
Log::notice("iDatabase::query(".$row['db_name'].",$query)");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($log) {
error_log("In ".$row['db_name'].", executed: $query", 0);
Log::notice("In ".$row['db_name'].", executed: $query");
}
}
}

@ -16,6 +16,7 @@
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$old_file_version = '1.8.8';
$new_file_version = '1.9.0';
@ -55,7 +56,6 @@ if (defined('SYSTEM_INSTALLATION')) {
// If this script has been included by index.php, not update_courses.php, so
// that we want to change the main databases as well...
$only_test = false;
$log = 0;
if (defined('SYSTEM_INSTALLATION')) {
if ($singleDbForm) {
@ -81,21 +81,18 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
foreach ($m_q_list as $query){
if ($only_test) {
error_log("Database::query($dbNameForm,$query)", 0);
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbNameForm, executed: $query", 0);
}
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -111,22 +108,19 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbStatsForm) > 40) {
error_log('Database name '.$dbStatsForm.' is too long, skipping', 0);
Log::error('Database name '.$dbStatsForm.' is too long, skipping');
} elseif (!in_array($dbStatsForm, $dblist)){
error_log('Database '.$dbStatsForm.' was not found, skipping', 0);
Log::error('Database '.$dbStatsForm.' was not found, skipping');
} else {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($s_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbStatsForm,$query)", 0);
Log::notice("iDatabase::query($dbStatsForm,$query)");
} else {
$res = Database::query($query);
if ($log) {
error_log("In $dbStatsForm, executed: $query", 0);
}
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -165,12 +159,12 @@ if (defined('SYSTEM_INSTALLATION')) {
);
if ($dbNameForm != $dbStatsForm) {
Database::select_db($dbStatsForm);
iDatabase::select_db($dbStatsForm);
foreach ($stats_table as $stat_table) {
$sql = "ALTER TABLE $dbStatsForm.$stat_table RENAME $dbNameForm.$stat_table";
Database::query($sql);
iDatabase::query($sql);
}
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
}
//Renaming user tables in the main DB
@ -200,19 +194,19 @@ if (defined('SYSTEM_INSTALLATION')) {
* without a database name
*/
if (strlen($dbUserForm) > 40) {
error_log('Database name '.$dbUserForm.' is too long, skipping', 0);
Log::error('Database name '.$dbUserForm.' is too long, skipping');
} elseif (!in_array($dbUserForm,$dblist)) {
error_log('Database '.$dbUserForm.' was not found, skipping', 0);
Log::error('Database '.$dbUserForm.' was not found, skipping');
} else {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach ($u_q_list as $query) {
if ($only_test) {
error_log("Database::query($dbUserForm,$query)", 0);
error_log("In $dbUserForm, executed: $query", 0);
Log::notice("iDatabase::query($dbUserForm,$query)");
Log::notice("In $dbUserForm, executed: $query");
} else {
$res = Database::query($query);
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -228,12 +222,12 @@ if (defined('SYSTEM_INSTALLATION')) {
);
if ($dbNameForm != $dbUserForm) {
Database::select_db($dbUserForm);
iDatabase::select_db($dbUserForm);
foreach($users_table as $table) {
$sql = "ALTER TABLE $dbUserForm.$table RENAME $dbNameForm.$table";
Database::query($sql);
iDatabase::query($sql);
}
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
}
}
@ -249,26 +243,26 @@ if (defined('SYSTEM_INSTALLATION')) {
// Get the courses databases queries list (c_q_list)
$c_q_list = get_sql_file_contents('migrate-db-'.$old_file_version.'-'.$new_file_version.'-pre.sql', 'course');
error_log('Starting migration: '.$old_file_version.' - '.$new_file_version);
Log::notice('Starting migration: '.$old_file_version.' - '.$new_file_version);
if (count($c_q_list) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
error_log('Database name '.$dbNameForm.' is too long, skipping', 0);
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif(!in_array($dbNameForm, $dblist)) {
error_log('Database '.$dbNameForm.' was not found, skipping', 0);
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
Database::select_db($dbNameForm);
$res = Database::query("SELECT id, code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
iDatabase::select_db($dbNameForm);
$res = iDatabase::query("SELECT id, code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL ORDER BY code");
if ($res === false) { die('Error while querying the courses list in update_db-1.8.6.2-1.8.7.inc.php'); }
$errors = array();
if (Database::num_rows($res) > 0) {
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = Database::fetch_array($res)) {
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
@ -277,22 +271,20 @@ if (defined('SYSTEM_INSTALLATION')) {
// Now use the $c_q_list
if (!$singleDbForm) { // otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
}
Log::notice('Course db ' . $row_course['db_name']);
foreach ($c_q_list as $query) {
if ($singleDbForm) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$row_course['db_name']}_$2$3", $query);
}
if ($only_test) {
error_log("Database::query(".$row_course['db_name'].",$query)", 0);
Log::notice("iDatabase::query(".$row_course['db_name'].",$query)");
} else {
$res = Database::query($query);
if ($log) {
error_log("In ".$row_course['db_name'].", executed: $query", 0);
}
$res = iDatabase::query($query);
if ($res === false) {
error_log('Error in '.$query.': '.Database::error());
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
@ -388,7 +380,8 @@ if (defined('SYSTEM_INSTALLATION')) {
'wiki_mailcue'
);
error_log('<<<------- Loading DB course '.$row_course['db_name'].' -------->>');
Log::notice('<<<------- Loading DB course '.$row_course['db_name'].' -------->>');
Install::message('<<<------- Loading DB course '.$row_course['db_name'].' -------->>');
$count = $old_count = 0;
foreach ($table_list as $table) {
@ -401,47 +394,48 @@ if (defined('SYSTEM_INSTALLATION')) {
if (!$singleDbForm) {
// otherwise just use the main one
Database::select_db($row_course['db_name']);
iDatabase::select_db($row_course['db_name']);
} else {
Database::select_db($dbNameForm);
iDatabase::select_db($dbNameForm);
}
//Count of rows
$sql = "SELECT count(*) FROM $old_table";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$old_count = 0;
if ($result) {
$row = Database::fetch_row($result);
$row = iDatabase::fetch_row($result);
$old_count = $row[0];
} else {
error_log("Seems that the table $old_table doesn't exists ");
Log::error("Seems that the table $old_table doesn't exists ");
}
error_log("#rows in $old_table: $old_count");
Log::notice("# rows in $old_table: $old_count");
$sql = "SELECT * FROM $old_table";
$result = Database::query($sql);
$result = iDatabase::query($sql);
$count = 0;
while($row = Database::fetch_array($result, 'ASSOC')) {
while($row = iDatabase::fetch_array($result, 'ASSOC')) {
$row['c_id'] = $course_id;
Database::select_db($dbNameForm);
$id = Database::insert($new_table, $row);
iDatabase::select_db($dbNameForm);
$id = iDatabase::insert($new_table, $row);
if (is_numeric($id)) {
$count++;
} else {
$errors[$old_table][] = $row;
}
}
error_log("# rows inserted in $new_table: $count");
Log::notice("# rows inserted in $new_table: $count");
if ($old_count != $count) {
error_log("ERROR count of new and old table doesn't match: $old_count - $new_table");
error_log("Check the results: ");
Log::error("ERROR count of new and old table doesn't match: $old_count - $new_table");
Log::error("Check the results: ");
Log::error(print_r($errors, 1));
error_log(print_r($errors, 1));
}
}
error_log('<<<------- end -------->>');
Log::notice('<<<------- end -------->>');
}
}
}

@ -12,6 +12,8 @@
/**
* Include mandatory libraries
*/
Log::notice('Entering file');
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; //check_name_exists()
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
@ -79,7 +81,7 @@ while ($row = Database::fetch_array($res)) {
$courses_dir_list[$row['code']] = $row['directory'];
}
if ($loglevel > 0) { error_log("Tables created/deleted for all courses", 0); }
if ($loglevel > 0) { Log::notice("Tables created/deleted for all courses"); }
/**
* The migration needs to take all data from the original learnpath tables and add them to the new
@ -89,12 +91,12 @@ if ($loglevel > 0) { error_log("Tables created/deleted for all courses", 0); }
// Test only one course
foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
if (strlen($courses_id_list[$course_code]) > 40) {
error_log('Database '.$courses_id_list[$course_code].' is too long, skipping', 0);
Log::error('Database '.$courses_id_list[$course_code].' is too long, skipping');
continue;
}
$incoherences = 0;
if ($loglevel > 0) { error_log("Now starting migration of learnpath tables from $db database...", 0); }
if ($loglevel > 0) { Log::notice("Now starting migration of learnpath tables from $db database..."); }
$lp_doc = $db.TABLE_DOCUMENT;
$lp_main = $db.TABLE_LEARNPATH_MAIN;
$lp_ids = array();
@ -117,13 +119,13 @@ foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
$sql_test = "SELECT * FROM $my_new_lp";
$res_test = Database::query($sql_test);
$sql_lp = "SELECT * FROM $lp_main";
if ($loglevel > 1) { error_log("$sql_lp", 0); }
if ($loglevel > 1) { Log::notice("$sql_lp"); }
$res_lp = Database::query($sql_lp);
if (!$res_lp or !$res_test) {
if ($loglevel > 1) {
error_log("+++Problem querying DB $lp_main+++ skipping (".Database::error().")", 0);
Log::error("+++Problem querying DB $lp_main+++ skipping (".Database::error().")");
if (!$res_test) {
error_log("This might be due to no existing table in the destination course", 0);
Log::error("This might be due to no existing table in the destination course");
}
}
continue;
@ -278,13 +280,13 @@ foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
case 'c':
// chapter-type prereq
$prereq_id = $lp_chap_items[$row['prereq_id']];
if (empty($prereq_id) && $loglevel > 1) { error_log("Could not find prereq chapter ".$row['prereq_id'], 0); }
if (empty($prereq_id) && $loglevel > 1) { Log::error("Could not find prereq chapter ".$row['prereq_id']); }
break;
case 'i':
default:
// item type prereq
$prereq_id = $lp_items[$parent_lps[$row['chapter_id']]][$row['prereq_id']];
if (empty($prereq_id) && $loglevel > 1) { error_log("Could not find prereq item ".$row['prereq_id'], 0); }
if (empty($prereq_id) && $loglevel > 1) { Log::error("Could not find prereq item ".$row['prereq_id']); }
break;
}
}
@ -511,7 +513,7 @@ foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
$sql_tool_upd = "UPDATE $tbl_tool " .
"SET link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id' " .
"WHERE id = ".$row_tool['id'];
error_log('New LP - Migration - Updating tool table: '.$sql_tool_upd, 0);
Log::notice('New LP - Migration - Updating tool table: '.$sql_tool_upd);
// Make sure there is a way of retrieving which links were updated (to revert)
fwrite($fh,$sql_tool_upd." AND link ='$link'");
fwrite($fh_revert, "UPDATE $tbl_tool SET link='$link' WHERE id=".$row_tool['id']." AND link ='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id';\n");
@ -532,7 +534,7 @@ foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
if (!empty($matches[3]) && (strtolower(substr($matches[3], -15)) == 'imsmanifest.xml') && !is_file(realpath(urldecode($matches[3])))) {
//echo "Removing link $link from tools<br />";
$sql_tool_upd = "DELETE FROM $tbl_tool WHERE id = ".$row_tool['id'];
error_log('New LP - Migration - Updating tool table (dead link): '.$sql_tool_upd, 0);
Log::notice('New LP - Migration - Updating tool table (dead link): '.$sql_tool_upd);
// Make sure there is a way of retrieving which links were updated (to revert)
fwrite($fh, $sql_tool_upd." AND link ='$link'");
fwrite($fh_revert, "INSERT INTO $tbl_tool (link) VALUES ('$link');\n");
@ -577,7 +579,7 @@ foreach ($courses_id_full_table_prefix_list as $course_code => $db) {
}
}
if ($loglevel > 0) { error_log("Done!".$msg, 0); }
if ($loglevel > 0) { Log::notice("Done!".$msg); }
//flush();
//ob_flush();
}
@ -600,7 +602,7 @@ fwrite($fh_res, "-- Recording resulting course homepages links changes for SCORM
* The migration needs to take all data from the scorm.scorm_main and scorm.scorm_sco_data tables
* and add them to the new lp, lp_view, lp_item and lp_item_view tables.
*/
if ($loglevel > 0) { error_log("Now starting migration of scorm tables from global SCORM database", 0); }
if ($loglevel > 0) { Log::notice("Now starting migration of scorm tables from global SCORM database"); }
$scorm_main = $dbScormForm.'.'.TABLE_SCORM_MAIN;
$scorm_item = $dbScormForm.'.'.TABLE_SCORM_SCO_DATA;
@ -617,7 +619,7 @@ $scorm_lp_paths = array();
Database::select_db($dbNameForm);
$course_main = TABLE_MAIN_COURSE;
$sql_crs = "SELECT * FROM $course_main WHERE target_course_code IS NULL";
if ($loglevel > 0) { error_log("$sql_crs", 0); }
if ($loglevel > 0) { Log::notice("$sql_crs"); }
$res_crs = Database::query($sql_crs);
$num = Database::num_rows($res_crs);
@ -627,7 +629,7 @@ $course_code_swap = '';
$scormdocuments_lps = array();
while ($course_row = Database::fetch_array($res_crs)) {
if ($loglevel > 0) { error_log("Now dealing with course ".$course_row['code']."...", 0); }
if ($loglevel > 0) { Log::notice("Now dealing with course ".$course_row['code']."..."); }
// Check the validity of this new course
$my_course_code = $course_row['code'];
@ -635,21 +637,21 @@ while ($course_row = Database::fetch_array($res_crs)) {
//$scormdocuments_lps = array();
$db_name = $courses_id_full_table_prefix_list[$my_course_code];
if (strlen($courses_id_list[$course_code]) > 40) {
error_log('Database '.$courses_id_list[$course_code].' is too long, skipping', 0);
Log::notice('Database '.$courses_id_list[$course_code].' is too long, skipping');
continue;
}
//echo "Now processing database $db_name<br />";
$tblscodoc = $db_name.TABLE_SCORMDOC;
$sql_scodoc = "SELECT path FROM $tblscodoc WHERE path IS NOT NULL AND path != ''";
if ($loglevel > 1) { error_log("$sql_scodoc", 0); }
if ($loglevel > 1) { Log::notice("$sql_scodoc"); }
$res_scodoc = Database::query($sql_scodoc);
while ($row_scodoc = Database::fetch_array($res_scodoc)) {
// Check if there's more than one slash in total
if (strpos($row_scodoc['path'], '/', 1) === false) {
$tmp_path = $row_scodoc['path'];
if ($loglevel > 1) { error_log("++Now opening $tmp_path", 0); }
if ($loglevel > 1) { Log::notice("++Now opening $tmp_path"); }
// Add a prefixing slash if there is none
if (substr($tmp_path, 0, 1) != '/') {
@ -670,17 +672,17 @@ while ($course_row = Database::fetch_array($res_crs)) {
// Avoid if contentTitle is not the name of an existing directory
} elseif (!is_file($courses_dir."/imsmanifest.xml")) {
// If the imsmanifest file was not found there
if ($loglevel > 2) { error_log(" !!imsmanifest.xml not found at scormdocument's $courses_dir/imsmanifest.xml, skipping", 0); }
if ($loglevel > 2) { Log::error(" !!imsmanifest.xml not found at scormdocument's $courses_dir/imsmanifest.xml, skipping"); }
// Try subdirectories on one level depth
if ($loglevel > 2) { error_log(" Trying subdirectories...", 0); }
if ($loglevel > 2) { Log::notice(" Trying subdirectories..."); }
$dh = opendir($courses_dir);
while ($entry = readdir($dh)) {
if (substr($entry, 0, 1) != '.') {
if (is_dir($courses_dir."/".$entry)) {
if (is_file($courses_dir."/".$entry."/imsmanifest.xml")) {
if ($loglevel > 2) { error_log(". .. and found $courses_dir/$entry/imsmanifest.xml!", 0); }
if ($loglevel > 2) { Log::notice(". .. and found $courses_dir/$entry/imsmanifest.xml!"); }
if (!in_array($tmp_path."/".$entry."/imsmanifest.xml",$scormdocuments_lps)) {
if ($loglevel > 2){ error_log(" Recording.<br />", 0); }
if ($loglevel > 2){ Log::notice(" Recording.<br />"); }
$scormdocuments_lps[] = $tmp_path."/".$entry;
}
}
@ -688,7 +690,7 @@ while ($course_row = Database::fetch_array($res_crs)) {
}
}
} else {
if ($loglevel > 2) { error_log(" Found scormdocument $tmp_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, treating it.", 0); }
if ($loglevel > 2) { Log::notice(" Found scormdocument $tmp_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, treating it."); }
$scormdocuments_lps[] = $tmp_path;
}
}
@ -734,9 +736,9 @@ while ($course_row = Database::fetch_array($res_crs)) {
//echo "Checking if manifest exists in ".$courses_dir.$entry."/imsmanifest.xml<br />";
if (is_file($courses_dir.$entry."/imsmanifest.xml")) {
//echo "found $courses_dir/$entry/imsmanifest.xml!<br />";
if ($loglevel > 2) { error_log(". .. and found $courses_dir/$entry/imsmanifest.xml!", 0); }
if ($loglevel > 2) { Log::notice(". .. and found $courses_dir/$entry/imsmanifest.xml!"); }
if (!in_array($entry."/imsmanifest.xml", $scormdocuments_lps)) {
if ($loglevel > 2) { error_log(" Recording.<br />", 0); }
if ($loglevel > 2) { Log::notice(" Recording.<br />"); }
//echo "Recording $entry<br />";
$scormdocuments_lps[] = $entry;
}
@ -754,7 +756,7 @@ while ($course_row = Database::fetch_array($res_crs)) {
$scorms[$my_course_code] = array();
$sql_paths = "SELECT * FROM $scorm_main WHERE dokeosCourse = '".$my_course_code."'";
if ($loglevel > 0) { error_log("$sql_paths", 0); }
if ($loglevel > 0) { Log::notice("$sql_paths"); }
$res_paths = Database::query($sql_paths);
$num = Database::num_rows($res_paths);
while ($scorm_row = Database::fetch_array($res_paths)) {
@ -767,16 +769,16 @@ while ($course_row = Database::fetch_array($res_crs)) {
if ($my_path == '/') {
$my_path = '';
}
if ($loglevel > 1) { error_log("++++Now opening $my_path", 0); }
if ($loglevel > 1) { Log::notice("++++Now opening $my_path"); }
if (!is_dir($courses_dir = $sys_course_path.''.$courses_dir_list[$my_course_code].'/scorm'.$my_path)) {
if ($loglevel > 1) { error_log("Path $my_content_id: $my_path doesn't exist in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, skipping", 0); }
if ($loglevel > 1) { Log::notice("Path $my_content_id: $my_path doesn't exist in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm, skipping"); }
continue;
// Avoid if contentTitle is not the name of an existing directory
} elseif (!is_file($sys_course_path.$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml")) {
if ($loglevel > 1) { error_log("!!imsmanifest.xml not found at ".$sys_course_path.$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml, skipping", 0); }
if ($loglevel > 1) { Log::notice("!!imsmanifest.xml not found at ".$sys_course_path.$courses_dir_list[$my_course_code].'/scorm'.$my_path."/imsmanifest.xml, skipping"); }
continue;
} else {
if ($loglevel > 1) { error_log("Found $my_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm".$mypath."/imsmanifest.xml, keeping it.", 0); }
if ($loglevel > 1) { Log::notice("Found $my_path in ".$sys_course_path.$courses_dir_list[$my_course_code]."/scorm".$mypath."/imsmanifest.xml, keeping it."); }
$scorms[$my_course_code][$my_path] = $my_content_id;
}
}
@ -785,7 +787,7 @@ while ($course_row = Database::fetch_array($res_crs)) {
foreach ($scormdocuments_lps as $path) {
if (!in_array($path,array_keys($scorms[$my_course_code]))) {
// Add it (-1 means no ID)
if ($loglevel > 1) { error_log("** Scormdocument path $path wasn't recorded yet. Added.", 0); }
if ($loglevel > 1) { Log::notice("** Scormdocument path $path wasn't recorded yet. Added."); }
$scorms[$my_course_code][$path] = -1;
}
}
@ -799,7 +801,7 @@ $my_count = 0;
foreach ($scorms as $mycourse => $my_paths) {
$my_count += count($my_paths);
}
if ($loglevel > 0) { error_log("---- Scorms array now contains ".$mycount." paths to migrate. Starting migration...", 0); }
if ($loglevel > 0) { Log::notice("---- Scorms array now contains ".$mycount." paths to migrate. Starting migration..."); }
/**
* Looping through the SCO_MAIN table for SCORM learnpath attached to courses
@ -811,9 +813,9 @@ foreach ($scorms as $my_course_code => $paths_list) {
$course_lp_done = array();
$db_name = $courses_id_full_table_prefix_list[$my_course_code];
foreach ($paths_list as $my_path => $old_id) {
if ($loglevel > 1) { error_log("Migrating lp $my_path from course $my_course_code...", 0); }
if ($loglevel > 1) { Log::notice("Migrating lp $my_path from course $my_course_code..."); }
$i_count ++;
//error_log('New LP - Migration script - Content '.$i_count.' on '.$num.' (course '.$scorm['dokeosCourse'].')',0);
//Log::notice('New LP - Migration script - Content '.$i_count.' on '.$num.' (course '.$scorm['dokeosCourse'].')');
// Check whether there is no embedded learnpaths into other learnpaths (one root-level and another embedded)
$embedded = false;
foreach ($course_lp_done as $tmp_lp) {
@ -824,7 +826,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
// Let it be
} else {
// This lp is embedded inside another lp who's imsmanifest exists, so prevent from parsing
if ($loglevel > 1) { error_log("LP $my_path is embedded into $tmp_lp, ignoring...", 0); }
if ($loglevel > 1) { Log::notice("LP $my_path is embedded into $tmp_lp, ignoring..."); }
$embedded = true;
continue;
}
@ -838,7 +840,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
$my_path = $my_path;
$my_name = basename($my_path);
if ($loglevel > 1) { error_log("Try importing LP $my_path from imsmanifest first as it is more reliable", 0); }
if ($loglevel > 1) { Log::notice("Try importing LP $my_path from imsmanifest first as it is more reliable"); }
// Setup the ims path (path to the imsmanifest.xml file)
//echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)<br />\n";
@ -853,7 +855,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
$oScorm = new scorm();
// Check whether imsmanifest.xml exists at this location. If not, ignore the imsmanifest.
// That should have been done before already, now.
if ($loglevel > 1) { error_log("Found imsmanifest ($ims), importing...", 0); }
if ($loglevel > 1) { Log::notice("Found imsmanifest ($ims), importing..."); }
if (!empty($sco_middle_path)) { $oScorm->subdir = $sco_middle_path; } //this sets the subdir for the scorm package inside the scorm dir
// Parse manifest file
$manifest = $oScorm->parse_manifest($ims);
@ -862,7 +864,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
//TODO: Add code to update the path in that new lp created, as it probably uses / where
// $sco_path_temp should be used...
$lp_ids[$my_content_id] = $oScorm->lp_id; // Contains the old LP ID => the new LP ID
if ($loglevel > 1) { error_log(" @@@ Created scorm lp ".$oScorm->lp_id." from imsmanifest [".$ims."] in course $my_course_code", 0); }
if ($loglevel > 1) { Log::notice(" @@@ Created scorm lp ".$oScorm->lp_id." from imsmanifest [".$ims."] in course $my_course_code"); }
$lp_course[$my_content_id] = $courses_id_list[$my_course_code]; // Contains the old learnpath ID => the course DB name
$lp_course_code[$my_content_id] = $my_course_code;
$max_dsp_lp++;
@ -943,7 +945,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
} else {
//echo "Could not find $ims... Proceeding from database...(line ".__LINE__.")<br />";
if ($loglevel > 1) { error_log("This is a normal SCORM path", 0); }
if ($loglevel > 1) { Log::notice("This is a normal SCORM path"); }
$scorm_lp_paths[$my_content_id]['path'] = $my_path;
//$scorm_lp_paths[$my_content_id]['ims'] = '';
$table_name = $db_name.$new_lp;
@ -970,7 +972,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
"'Unknown'," .
"'scorm_api.php'" .
")";
if ($loglevel > 1) { error_log("$sql_ins", 0); }
if ($loglevel > 1) { Log::notice("$sql_ins"); }
$sql_res = Database::query($sql_ins);
$in_id = Database::insert_id();
if (!$in_id) die('Could not insert scorm lp: '.$sql_ins);
@ -992,7 +994,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
// Check whether imsmanifest.xml exists at this location. If not, ignore the imsmanifest.
// That should have been done before already, now.
if (!is_file($scorm_lp_paths[$my_content_id]['ims'])) {
if ($loglevel > 1) { error_log("!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id], 0); }
if ($loglevel > 1) { Log::notice("!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id]); }
$manifest = false;
} else {
//echo "Parsing ".$scorm_lp_paths[$my_content_id]['ims']."<br />\n";
@ -1007,7 +1009,7 @@ foreach ($scorms as $my_course_code => $paths_list) {
"SET name = '$my_lp_title', " .
"default_encoding = '".strtoupper($oScorm->manifest_encoding)."' " .
"WHERE id = ".$lp_ids[$my_content_id];
if ($loglevel > 1) { error_log("Updating title and encoding: ".$my_sql, 0); }
if ($loglevel > 1) { Log::notice("Updating title and encoding: ".$my_sql); }
$my_res = Database::query($my_sql);
}
}
@ -1278,5 +1280,5 @@ foreach ($scorms as $my_course_code => $paths_list) {
fclose($fh);
fclose($fh_revert);
fclose($fh_res);
if ($loglevel > 0) { error_log("All done!", 0); }
if ($loglevel > 0) { Log::notice("All done!"); }
//echo "</body></html>";

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -17,137 +18,134 @@
*
* @package chamilo.install
*/
Log::notice('Entering file');
function insert_db($db_name, $folder_name, $text) {
// TODO: The (global?) variable $_course has not been declared/initialized.
$_course['dbName'] = $db_name;
function insert_db($db_name, $folder_name, $text)
{
$doc_id = add_document_180($_course, '/'.$folder_name, 'folder', 0, api_ucfirst($text));
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', 1);
// TODO: The (global?) variable $_course has not been declared/initialized.
$_course['dbName'] = $db_name;
$doc_id = add_document_180($_course, '/' . $folder_name, 'folder', 0, api_ucfirst($text));
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', 1);
}
if (defined('SYSTEM_INSTALLATION')) {
$sys_course_path = $pathForm.'courses/';
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
Database::select_db($dbNameForm);
$db_name = $dbNameForm;
$sql = "SELECT * FROM course";
error_log('Getting courses for files updates: '.$sql, 0);
$result = Database::query($sql);
while ($courses_directories = Database::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path.$courses_directories["directory"]."/";
$db_name = $courses_directories["db_name"];
$origCRS = $updatePath.'courses/'.$courses_directories["directory"];
if (!is_dir($origCRS)) {
error_log('Directory '.$origCRS.' does not exist. Skipping.', 0);
continue;
}
// Move everything to the new hierarchy (from old path to new path)
error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories["directory"], 0);
rename($origCRS,$sys_course_path.$courses_directories["directory"]);
error_log('Creating dirs in '.$currentCourseRepositorySys, 0);
// FOLDER DOCUMENT
// document > audio
if (!is_dir($currentCourseRepositorySys."document/audio")) {
mkdir($currentCourseRepositorySys."document/audio", $perm);
insert_db($db_name, "audio", get_lang('Audio'));
}
// document > flash
if (!is_dir($currentCourseRepositorySys."document/flash")) {
mkdir($currentCourseRepositorySys."document/flash", $perm);
insert_db($db_name,"flash",get_lang('Flash'));
}
// document > images
if (!is_dir($currentCourseRepositorySys."document/images")) {
mkdir($currentCourseRepositorySys."document/images", $perm);
insert_db($db_name,"images",get_lang('Images'));
}
// document > video
if (!is_dir($currentCourseRepositorySys."document/video")) {
mkdir($currentCourseRepositorySys."document/video", $perm);
insert_db($db_name,"video",get_lang('Video'));
}
// document > video > flv
if (!is_dir($currentCourseRepositorySys."document/video/flv")) {
mkdir($currentCourseRepositorySys."document/video/flv", $perm);
insert_db($db_name,"video",get_lang('Video')." (flv)");
}
// FOLDER UPLOAD
// upload
if (!is_dir($currentCourseRepositorySys."upload")) {
mkdir($currentCourseRepositorySys."upload", $perm);
}
// upload > blog
if (!is_dir($currentCourseRepositorySys."upload/blog")) {
mkdir($currentCourseRepositorySys."upload/blog", $perm);
}
// upload > forum
if (!is_dir($currentCourseRepositorySys."upload/forum")) {
mkdir($currentCourseRepositorySys."upload/forum", $perm);
}
// upload > test
if (!is_dir($currentCourseRepositorySys."upload/test")) {
mkdir($currentCourseRepositorySys."upload/test", $perm);
}
// Updating index file in courses directories to change claroline/ into main/
$content = '<?php'."\n".
'$cidReq="'.$courses_directories['code'].'";'."\n" .
'$dbname="'.$courses_directories['db_name'].'";'."\n" .
'include("../../main/course_home/course_home.php");'."\n" .
'?>';
unlink($currentCourseRepositorySys.'index.php');
$fp = @ fopen($currentCourseRepositorySys.'index.php', 'w');
if ($fp) {
error_log('Writing redirection file in '.$currentCourseRepositorySys.'index.php', 0);
fwrite($fp, $content);
fclose($fp);
} else {
error_log('Could not open file '.$currentCourseRepositorySys.'index.php', 0);
}
}
// Write the config file
write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.php');
// Write a distribution file with the config as a backup for the admin
write_system_config_file(api_get_path(CONFIGURATION_PATH).'configuration.dist.php');
// Write a .htaccess file in the course repository
write_courses_htaccess_file($urlAppendPath);
copy($updatePath.'claroline/inc/conf/add_course.conf.php', $pathForm.'main/inc/conf/add_course.conf.php');
copy($updatePath.'claroline/inc/conf/course_info.conf.php', $pathForm.'main/inc/conf/course_info.conf.php');
copy($updatePath.'claroline/inc/conf/mail.conf.php', $pathForm.'main/inc/conf/mail.conf.php');
copy($updatePath.'claroline/inc/conf/profile.conf.inc.php', $pathForm.'main/inc/conf/profile.conf.php');
error_log('Renaming '.$updatePath.'claroline/upload/users to '.$pathForm.'main/upload/users', 0);
rename($updatePath.'claroline/upload/users', $pathForm.'main/upload/users');
error_log('Renaming '.$updatePath.'claroline/upload/audio to '.$pathForm.'main/upload/audio', 0);
rename($updatePath.'claroline/upload/audio', $pathForm.'main/upload/audio');
error_log('Renaming '.$updatePath.'claroline/upload/images to '.$pathForm.'main/upload/images', 0);
rename($updatePath.'claroline/upload/images', $pathForm.'main/upload/images');
error_log('Renaming '.$updatePath.'claroline/upload/linked_files to '.$pathForm.'main/upload/linked_files', 0);
rename($updatePath.'claroline/upload/linked_files', $pathForm.'main/upload/linked_files');
error_log('Renaming '.$updatePath.'claroline/upload/video to '.$pathForm.'main/upload/video', 0);
rename($updatePath.'claroline/upload/video', $pathForm.'main/upload/video');
$sys_course_path = $pathForm . 'courses/';
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
Database::select_db($dbNameForm);
$db_name = $dbNameForm;
$sql = "SELECT * FROM course";
Log::notice('Getting courses for files updates: ' . $sql);
$result = Database::query($sql);
while ($courses_directories = Database::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path . $courses_directories["directory"] . "/";
$db_name = $courses_directories["db_name"];
$origCRS = $updatePath . 'courses/' . $courses_directories["directory"];
if (!is_dir($origCRS)) {
Log::error('Directory ' . $origCRS . ' does not exist. Skipping.');
continue;
}
// Move everything to the new hierarchy (from old path to new path)
Log::notice('Renaming ' . $origCRS . ' to ' . $sys_course_path . $courses_directories["directory"]);
rename($origCRS, $sys_course_path . $courses_directories["directory"]);
Log::notice('Creating dirs in ' . $currentCourseRepositorySys);
// FOLDER DOCUMENT
// document > audio
if (!is_dir($currentCourseRepositorySys . "document/audio")) {
mkdir($currentCourseRepositorySys . "document/audio", $perm);
insert_db($db_name, "audio", get_lang('Audio'));
}
// document > flash
if (!is_dir($currentCourseRepositorySys . "document/flash")) {
mkdir($currentCourseRepositorySys . "document/flash", $perm);
insert_db($db_name, "flash", get_lang('Flash'));
}
// document > images
if (!is_dir($currentCourseRepositorySys . "document/images")) {
mkdir($currentCourseRepositorySys . "document/images", $perm);
insert_db($db_name, "images", get_lang('Images'));
}
// document > video
if (!is_dir($currentCourseRepositorySys . "document/video")) {
mkdir($currentCourseRepositorySys . "document/video", $perm);
insert_db($db_name, "video", get_lang('Video'));
}
// document > video > flv
if (!is_dir($currentCourseRepositorySys . "document/video/flv")) {
mkdir($currentCourseRepositorySys . "document/video/flv", $perm);
insert_db($db_name, "video", get_lang('Video') . " (flv)");
}
// FOLDER UPLOAD
// upload
if (!is_dir($currentCourseRepositorySys . "upload")) {
mkdir($currentCourseRepositorySys . "upload", $perm);
}
// upload > blog
if (!is_dir($currentCourseRepositorySys . "upload/blog")) {
mkdir($currentCourseRepositorySys . "upload/blog", $perm);
}
// upload > forum
if (!is_dir($currentCourseRepositorySys . "upload/forum")) {
mkdir($currentCourseRepositorySys . "upload/forum", $perm);
}
// upload > test
if (!is_dir($currentCourseRepositorySys . "upload/test")) {
mkdir($currentCourseRepositorySys . "upload/test", $perm);
}
// Updating index file in courses directories to change claroline/ into main/
$content = '<?php' . "\n" .
'$cidReq="' . $courses_directories['code'] . '";' . "\n" .
'$dbname="' . $courses_directories['db_name'] . '";' . "\n" .
'include("../../main/course_home/course_home.php");' . "\n" .
'?>';
unlink($currentCourseRepositorySys . 'index.php');
$fp = @ fopen($currentCourseRepositorySys . 'index.php', 'w');
if ($fp) {
Log::error('Writing redirection file in ' . $currentCourseRepositorySys . 'index.php');
fwrite($fp, $content);
fclose($fp);
} else {
Log::error('Could not open file ' . $currentCourseRepositorySys . 'index.php');
}
}
// Write the config file
write_system_config_file(api_get_path(CONFIGURATION_PATH) . 'configuration.php');
// Write a distribution file with the config as a backup for the admin
write_system_config_file(api_get_path(CONFIGURATION_PATH) . 'configuration.dist.php');
// Write a .htaccess file in the course repository
write_courses_htaccess_file($urlAppendPath);
copy($updatePath . 'claroline/inc/conf/add_course.conf.php', $pathForm . 'main/inc/conf/add_course.conf.php');
copy($updatePath . 'claroline/inc/conf/course_info.conf.php', $pathForm . 'main/inc/conf/course_info.conf.php');
copy($updatePath . 'claroline/inc/conf/mail.conf.php', $pathForm . 'main/inc/conf/mail.conf.php');
copy($updatePath . 'claroline/inc/conf/profile.conf.inc.php', $pathForm . 'main/inc/conf/profile.conf.php');
Log::notice('Renaming ' . $updatePath . 'claroline/upload/users to ' . $pathForm . 'main/upload/users');
rename($updatePath . 'claroline/upload/users', $pathForm . 'main/upload/users');
Log::notice('Renaming ' . $updatePath . 'claroline/upload/audio to ' . $pathForm . 'main/upload/audio');
rename($updatePath . 'claroline/upload/audio', $pathForm . 'main/upload/audio');
Log::notice('Renaming ' . $updatePath . 'claroline/upload/images to ' . $pathForm . 'main/upload/images');
rename($updatePath . 'claroline/upload/images', $pathForm . 'main/upload/images');
Log::notice('Renaming ' . $updatePath . 'claroline/upload/linked_files to ' . $pathForm . 'main/upload/linked_files');
rename($updatePath . 'claroline/upload/linked_files', $pathForm . 'main/upload/linked_files');
Log::notice('Renaming ' . $updatePath . 'claroline/upload/video to ' . $pathForm . 'main/upload/video');
rename($updatePath . 'claroline/upload/video', $pathForm . 'main/upload/video');
} else {
echo 'You are not allowed here !';
echo 'You are not allowed here !';
}

@ -17,6 +17,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

@ -17,6 +17,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -17,108 +18,104 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH).'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w');
$found_version = false;
$found_stable = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n";
} elseif (stripos($line,'$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} elseif (stripos($line, '?>') !== false) {
// Ignore the line
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable ? 'true' : 'false').';'."\r\n");
}
fwrite($fh, '?>');
fclose($fh);
$sys_course_path = $pathForm.'courses/';
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
//// Linking (The following line is disabled, connection has been already done)
//$res = @Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm));
//Database::select_db($dbNameForm, $link);
Database::select_db($dbNameForm);
$db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course";
error_log('Getting courses for files updates: '.$sql, 0);
$result = Database::query($sql);
while ($courses_directories = Database::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
$db_name = $courses_directories['db_name'];
$origCRS = $updatePath.'courses/'.$courses_directories['directory'];
if (!is_dir($origCRS)) {
error_log('Directory '.$origCRS.' does not exist. Skipping.', 0);
continue;
}
// Move everything to the new hierarchy (from old path to new path)
error_log('Renaming '.$origCRS.' to '.$sys_course_path.$courses_directories['directory'], 0);
rename($origCRS,$sys_course_path.$courses_directories['directory']);
error_log('Creating dirs in '.$currentCourseRepositorySys, 0);
// DOCUMENT FOLDER
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH) . 'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH) . 'configuration.php', 'w');
$found_version = false;
$found_stable = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \'' . $new_version . '\';' . "\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n";
} elseif (stripos($line, '$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \'' . ($userPasswordCrypted) . '\';' . "\r\n";
} elseif (stripos($line, '?>') !== false) {
// Ignore the line
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'dokeos_version\'] = \'' . $new_version . '\';' . "\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'dokeos_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n");
}
fwrite($fh, '?>');
fclose($fh);
$sys_course_path = $pathForm . 'courses/';
//$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
//// Linking (The following line is disabled, connection has been already done)
//$res = @iDatabase::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm));
//iDatabase::select_db($dbNameForm, $link);
iDatabase::select_db($dbNameForm);
$db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course";
Log::notice('Getting courses for files updates: ' . $sql);
$result = iDatabase::query($sql);
while ($courses_directories = iDatabase::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path . $courses_directories['directory'] . '/';
$db_name = $courses_directories['db_name'];
$origCRS = $updatePath . 'courses/' . $courses_directories['directory'];
if (!is_dir($origCRS)) {
Log::error('Directory ' . $origCRS . ' does not exist. Skipping.');
continue;
}
// Move everything to the new hierarchy (from old path to new path)
Log::notice('Renaming ' . $origCRS . ' to ' . $sys_course_path . $courses_directories['directory']);
rename($origCRS, $sys_course_path . $courses_directories['directory']);
Log::notice('Creating dirs in ' . $currentCourseRepositorySys);
// DOCUMENT FOLDER
// document > shared_folder
if (!is_dir($currentCourseRepositorySys."document/shared_folder")) {
mkdir($currentCourseRepositorySys."document/shared_folder", $perm);
if (!is_dir($currentCourseRepositorySys . "document/shared_folder")) {
mkdir($currentCourseRepositorySys . "document/shared_folder", $perm);
}
// UPLOAD FOLDER
// upload > forum > images
if (!is_dir($currentCourseRepositorySys."upload/forum/images")) {
mkdir($currentCourseRepositorySys."upload/forum/images", $perm);
}
// upload > learning_path
if (!is_dir($currentCourseRepositorySys."upload/learning_path")) {
mkdir($currentCourseRepositorySys."upload/learning_path", $perm);
}
// UPLOAD FOLDER
// upload > forum > images
if (!is_dir($currentCourseRepositorySys . "upload/forum/images")) {
mkdir($currentCourseRepositorySys . "upload/forum/images", $perm);
}
// upload > learning_path > images
if (!is_dir($currentCourseRepositorySys."upload/learning_path/images")) {
mkdir($currentCourseRepositorySys."upload/learning_path/images", $perm);
}
// upload > learning_path
if (!is_dir($currentCourseRepositorySys . "upload/learning_path")) {
mkdir($currentCourseRepositorySys . "upload/learning_path", $perm);
}
// upload > calendar
if (!is_dir($currentCourseRepositorySys."upload/calendar")) {
mkdir($currentCourseRepositorySys."upload/calendar", $perm);
}
// upload > learning_path > images
if (!is_dir($currentCourseRepositorySys . "upload/learning_path/images")) {
mkdir($currentCourseRepositorySys . "upload/learning_path/images", $perm);
}
// upload > calendar > images
if (!is_dir($currentCourseRepositorySys."upload/calendar/images")) {
mkdir($currentCourseRepositorySys."upload/calendar/images", $perm);
}
}
// upload > calendar
if (!is_dir($currentCourseRepositorySys . "upload/calendar")) {
mkdir($currentCourseRepositorySys . "upload/calendar", $perm);
}
// upload > calendar > images
if (!is_dir($currentCourseRepositorySys . "upload/calendar/images")) {
mkdir($currentCourseRepositorySys . "upload/calendar/images", $perm);
}
}
} else {
echo 'You are not allowed here !';
echo 'You are not allowed here !';
}

@ -17,6 +17,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -11,78 +12,77 @@
* @package chamilo.install
*/
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH).'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH).'configuration.php', 'w');
$found_version = false;
$found_stable = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n";
} elseif (stripos($line,'$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \''.($userPasswordCrypted).'\';'."\r\n";
} elseif (stripos($line, '?>') !== false) {
//ignore the line
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'dokeos_version\'] = \''.$new_version.'\';'."\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'dokeos_stable\'] = '.($new_version_stable?'true':'false').';'."\r\n");
}
fwrite($fh, '?>');
fclose($fh);
Log::notice('Entering file');
$sys_course_path = $pathForm.'courses/';
if (defined('SYSTEM_INSTALLATION')) {
$perm = api_get_permissions_for_new_directories();
// Edit the configuration file
$file = file(api_get_path(CONFIGURATION_PATH) . 'configuration.php');
$fh = fopen(api_get_path(CONFIGURATION_PATH) . 'configuration.php', 'w');
$found_version = false;
$found_stable = false;
foreach ($file as $line) {
$ignore = false;
if (stripos($line, '$_configuration[\'dokeos_version\']') !== false) {
$found_version = true;
$line = '$_configuration[\'dokeos_version\'] = \'' . $new_version . '\';' . "\r\n";
} elseif (stripos($line, '$_configuration[\'dokeos_stable\']') !== false) {
$found_stable = true;
$line = '$_configuration[\'dokeos_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n";
} elseif (stripos($line, '$userPasswordCrypted') !== false) {
$line = '$userPasswordCrypted = \'' . ($userPasswordCrypted) . '\';' . "\r\n";
} elseif (stripos($line, '?>') !== false) {
//ignore the line
$ignore = true;
}
if (!$ignore) {
fwrite($fh, $line);
}
}
if (!$found_version) {
fwrite($fh, '$_configuration[\'dokeos_version\'] = \'' . $new_version . '\';' . "\r\n");
}
if (!$found_stable) {
fwrite($fh, '$_configuration[\'dokeos_stable\'] = ' . ($new_version_stable ? 'true' : 'false') . ';' . "\r\n");
}
fwrite($fh, '?>');
fclose($fh);
// The following line is disabled, connection has been already done
//$link = Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm));
$sys_course_path = $pathForm . 'courses/';
//Database::select_db($dbNameForm, $link);
Database::select_db($dbNameForm);
$perm = api_get_permissions_for_new_directories();
$db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course";
error_log('Getting courses for files updates: '.$sql, 0);
$result = Database::query($sql);
// The following line is disabled, connection has been already done
//$link = iDatabase::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm));
//iDatabase::select_db($dbNameForm, $link);
iDatabase::select_db($dbNameForm);
if (Database::num_rows($result) > 0) {
while ($courses_directories = Database::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path.$courses_directories['directory'].'/';
// upload > announcements
if (!is_dir($currentCourseRepositorySys."upload/announcements")){
mkdir($currentCourseRepositorySys."upload/announcements", $perm);
}
$db_name = $dbNameForm;
$sql = "SELECT * FROM $db_name.course";
Log::notice('Getting courses for files updates: ' . $sql);
$result = iDatabase::query($sql);
// upload > announcements > images
if (!is_dir($currentCourseRepositorySys."upload/announcements/images")) {
mkdir($currentCourseRepositorySys."upload/announcements/images", $perm);
}
}
}
if (iDatabase::num_rows($result) > 0) {
while ($courses_directories = iDatabase::fetch_array($result)) {
$currentCourseRepositorySys = $sys_course_path . $courses_directories['directory'] . '/';
// upload > announcements
if (!is_dir($currentCourseRepositorySys . "upload/announcements")) {
mkdir($currentCourseRepositorySys . "upload/announcements", $perm);
}
//// Create a specific directory for global thumbails
// home > default_platform_document > template_thumb
if (!is_dir($pathForm.'home/default_platform_document/template_thumb')) {
mkdir($pathForm.'home/default_platform_document/template_thumb', $perm);
}
// upload > announcements > images
if (!is_dir($currentCourseRepositorySys . "upload/announcements/images")) {
mkdir($currentCourseRepositorySys . "upload/announcements/images", $perm);
}
}
}
//// Create a specific directory for global thumbails
// home > default_platform_document > template_thumb
if (!is_dir($pathForm . 'home/default_platform_document/template_thumb')) {
mkdir($pathForm . 'home/default_platform_document/template_thumb', $perm);
}
} else {
echo 'You are not allowed here !';
echo 'You are not allowed here !';
}

@ -11,6 +11,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

@ -11,6 +11,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

@ -11,6 +11,8 @@
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
// Edit the configuration file

Loading…
Cancel
Save