From e377125c02afc42635619dafca4bafab88c23271 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 4 Aug 2015 16:12:15 +0200 Subject: [PATCH] Fix upgrade process, remove chamilo.class.php --- index.php | 2 - .../lib/shibboleth_session.class.php | 3 +- main/inc/global.inc.php | 6 +- main/inc/lib/chamilo.class.php | 28 ------- main/inc/lib/database.lib.php | 45 ++-------- main/inc/lib/portfolio.class.php | 2 +- main/install/install.lib.php | 20 ++--- .../CoreBundle/Composer/ScriptHandler.php | 84 ++++++++++++++++++- .../DBAL/Types/UTCDateTimeType.php | 8 ++ tests/main/inc/lib/main_api.lib.test.php | 8 -- 10 files changed, 106 insertions(+), 100 deletions(-) delete mode 100755 main/inc/lib/chamilo.class.php diff --git a/index.php b/index.php index 4862b12bd1..b6c87ae579 100755 --- a/index.php +++ b/index.php @@ -103,8 +103,6 @@ if (!empty($_POST['submitAuth'])) { Session::write('user_last_login_datetime',$user_last_login_datetime); } } - Database::free_result($result_last_login); - //Event::event_login(); } // End login -- if ($_POST['submitAuth']) diff --git a/main/auth/shibboleth/lib/shibboleth_session.class.php b/main/auth/shibboleth/lib/shibboleth_session.class.php index 276ed7495f..8fc72b5559 100755 --- a/main/auth/shibboleth/lib/shibboleth_session.class.php +++ b/main/auth/shibboleth/lib/shibboleth_session.class.php @@ -2,7 +2,6 @@ namespace Shibboleth; -use Chamilo; use ChamiloSession as Session; use Database; @@ -68,7 +67,7 @@ class ShibbolethSession $this->logout(); - Chamilo::session()->start(); + Session::instance(); Session::write('_uid', $_uid); global $_user; diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index afac87db7f..e8e725514b 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -81,9 +81,6 @@ define('USERNAME_MAX_LENGTH', $defaultUserNameLength); // Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI']. api_request_uri(); -// This is for compatibility with MAC computers. -ini_set('auto_detect_line_endings', '1'); - // Include the libraries that are necessary everywhere require_once __DIR__.'/../../vendor/autoload.php'; @@ -91,7 +88,6 @@ require_once __DIR__.'/../../vendor/autoload.php'; $libraryPath = api_get_path(LIBRARY_PATH); // @todo convert this libs in classes - require_once $libraryPath.'database.constants.inc.php'; require_once $libraryPath.'text.lib.php'; require_once $libraryPath.'array.lib.php'; @@ -191,7 +187,7 @@ $charset = 'UTF-8'; \Patchwork\Utf8\Bootup::initAll(); // Start session after the internationalization library has been initialized. -Chamilo::session()->start($alreadyInstalled); +ChamiloSession::instance()->start($alreadyInstalled); // Remove quotes added by PHP - get_magic_quotes_gpc() is deprecated in PHP 5 see #2970 diff --git a/main/inc/lib/chamilo.class.php b/main/inc/lib/chamilo.class.php deleted file mode 100755 index 10ab8bfcc5..0000000000 --- a/main/inc/lib/chamilo.class.php +++ /dev/null @@ -1,28 +0,0 @@ - for the Univesity of Geneva - */ -class Chamilo -{ - /** - * - * @return ChamiloSession - */ - static function session() - { - return ChamiloSession::instance(); - } -} diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index aed17a7636..8d46b2d43e 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; +use Chamilo\CoreBundle\DoctrineExtensions\DBAL\Types\UTCDateTimeType; /** * Class Database @@ -150,7 +151,10 @@ class Database $sysPath."vendor/gedmo/doctrine-extensions/lib" ); - Type::overrideType('datetime', 'Chamilo\CoreBundle\DoctrineExtensions\DBAL\Types\UTCDateTimeType'); + Type::overrideType( + Type::DATETIME, + 'Chamilo\CoreBundle\DoctrineExtensions\DBAL\Types\UTCDateTimeType' + ); $listener = new \Gedmo\Timestampable\TimestampableListener(); $entityManager->getEventManager()->addEventSubscriber($listener); @@ -160,40 +164,10 @@ class Database $listener = new \Gedmo\Sortable\SortableListener(); $entityManager->getEventManager()->addEventSubscriber($listener); + $connection = $entityManager->getConnection(); - $this->setConnection($entityManager->getConnection()); + $this->setConnection($connection); $this->setManager($entityManager); - - // A MySQL-specific implementation. - /*if (!isset($parameters['server'])) { - $parameters['server'] = @ini_get('mysql.default_host'); - if (empty($parameters['server'])) { - $parameters['server'] = 'localhost:3306'; - } - } - if (!isset($parameters['username'])) { - $parameters['username'] = @ini_get('mysql.default_user'); - } - if (!isset($parameters['password'])) { - $parameters['password'] = @ini_get('mysql.default_password'); - } - if (!isset($parameters['new_link'])) { - $parameters['new_link'] = false; - } - if (!isset($parameters['client_flags']) || empty($parameters['client_flags'])) { - $parameters['client_flags'] = 0; - } - - $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);*/ } /** @@ -224,7 +198,6 @@ class Database return trim($string, "'"); } - /** * Gets the array from a SQL result (as returned by Database::query) * @@ -331,7 +304,7 @@ class Database } /** - * @param $query + * @param string $query * * @return Statement * @@ -351,7 +324,7 @@ class Database */ public static function customOptionToDoctrineOption($option) { - switch($option) { + switch ($option) { case 'ASSOC': return PDO::FETCH_ASSOC; break; diff --git a/main/inc/lib/portfolio.class.php b/main/inc/lib/portfolio.class.php index e100d9a1fb..e300f170e4 100755 --- a/main/inc/lib/portfolio.class.php +++ b/main/inc/lib/portfolio.class.php @@ -287,7 +287,7 @@ class PortfolioController */ function course_code() { - return Chamilo::session()->course()->code(); + return ChamiloSession::instance()->course()->code(); } /** diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 73395a0b8e..1d948880a6 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -1944,6 +1944,11 @@ function migrate($chamiloVersion, EntityManager $manager) } } +/** +* @param EntityManager $em + * +* @throws \Doctrine\DBAL\DBALException + */ function fixIds(EntityManager $em) { $connection = $em->getConnection(); @@ -2174,7 +2179,6 @@ function fixIds(EntityManager $em) } } - $sql = "SELECT * FROM groups"; $result = $connection->executeQuery($sql); $groups = $result->fetchAll(); @@ -2377,7 +2381,6 @@ function fixIds(EntityManager $em) } } } - } /** @@ -2470,19 +2473,6 @@ function finishInstallation( false //$isAdmin = false ); -/* - // Insert admin and Anonymous users. - $uniqueAdmin = sha1(uniqid(null, true)); - $uniqueAnon = sha1(uniqid(null, true)); - $sql = "INSERT INTO user (user_id, lastname, firstname, username, username_canonical, salt, password, auth_source, email, status, official_code, phone, creator_id, registration_date, expiration_date,active,openid,language) VALUES - (1, '$adminLastName','$adminFirstName','$loginForm','$loginForm', '$uniqueAdmin', '$encryptPassword','".PLATFORM_AUTH_SOURCE."','$emailForm',1,'ADMIN','$adminPhoneForm',1,NOW(),NULL,'1',NULL,'$languageForm'), - (2, 'Anonymous', 'Joe', 'anon', 'anon', '$uniqueAnon', '', 'platform', 'anonymous@localhost', 6, 'anonymous', NULL, 1, NOW(), NULL, 1,NULL,'$languageForm')"; - //Database::query($sql);*/ - - // Insert user as admin - //$sql = "INSERT INTO admin VALUES(1, 1)"; - //Database::query($sql); - // Set default language $sql = "UPDATE language SET available=1 WHERE dokeos_folder = '$languageForm'"; Database::query($sql); diff --git a/src/Chamilo/CoreBundle/Composer/ScriptHandler.php b/src/Chamilo/CoreBundle/Composer/ScriptHandler.php index ea17e99aa1..8965f8c98e 100644 --- a/src/Chamilo/CoreBundle/Composer/ScriptHandler.php +++ b/src/Chamilo/CoreBundle/Composer/ScriptHandler.php @@ -26,10 +26,88 @@ class ScriptHandler */ public static function deleteOldFilesFrom19x() { - $path = __DIR__.'/../../../../main/inc/lib/symfony/'; - if (is_dir($path) && is_writable($path)) { - self::rmdirr($path); + $paths = [ + __DIR__.'/../../../../main/conference/', + __DIR__.'/../../../../main/course_notice/', + __DIR__.'/../../../../main/metadata/', + __DIR__.'/../../../../main/reservation/', + __DIR__.'/../../../../main/inc/lib/symfony/', + __DIR__.'/../../../../main/inc/entity/', + //__DIR__.'/../../../../main/inc/lib/phpdocx/', + __DIR__.'/../../../../main/inc/lib/phpqrcode/', + __DIR__.'/../../../../main/inc/lib/fckeditor', + //__DIR__.'/../../../../main/inc/lib/htmlpurifier/', + __DIR__.'/../../../../main/inc/lib/mpdf/', + __DIR__.'/../../../../main/inc/lib/symfony/', + __DIR__.'/../../../../main/inc/lib/system/media/renderer', + __DIR__.'/../../../../main/inc/lib/system/io', + __DIR__.'/../../../../main/inc/lib/system/net', + __DIR__.'/../../../../main/inc/lib/system/text/', + __DIR__.'/../../../../main/inc/lib/tools/', + __DIR__.'/../../../../main/inc/lib/pchart/', + ]; + + $files = [ + + __DIR__.'/../../../../main/admin/statistics/statistics.lib.php', + __DIR__.'/../../../../main/inc/lib/main_api.lib.php', + __DIR__.'/../../../../main/exercice/export/scorm/scorm_export.php', + __DIR__.'/../../../../main/exercice/export/qti/qti_export.php', + __DIR__.'/../../../../main/exercice/export/qti/qti_classes.php', + //__DIR__.'/../../../../main/inc/lib/nusoap/class.soapclient.php', + __DIR__.'/../../../../main/inc/lib/nusoap/nusoap.php', + __DIR__.'/../../../../main/admin/admin_page.class.php', + __DIR__.'/../../../../main/inc/lib/autoload.class.php', + __DIR__.'/../../../../main/inc/autoload.inc.php', + __DIR__.'/../../../../main/inc/lib/uri.class.php', + __DIR__.'/../../../../main/inc/lib/db.class.php', + __DIR__.'/../../../../main/install/i_database.class.php', + __DIR__.'/../../../../main/inc/lib/phpmailer/test/phpmailerTest.php', + __DIR__.'/../../../../main/inc/lib/xht.lib.php', + __DIR__.'/../../../../main/inc/lib/xmd.lib.php', + __DIR__.'/../../../../main/inc/lib/entity.class.php', + __DIR__.'/../../../../main/inc/lib/entity_repository.class.php', + __DIR__.'/../../../../main/install/install.class.php', + __DIR__.'/../../../../main/inc/lib/javascript.class.php', + __DIR__.'/../../../../main/inc/lib/course.class.php', + __DIR__.'/../../../../main/inc/lib/document.class.php', + __DIR__.'/../../../../main/inc/lib/item_property.class.php', + __DIR__.'/../../../../main/inc/lib/chamilo.class.php', + __DIR__.'/../../../../main/inc/lib/events.lib.inc.php', + __DIR__.'/../../../../main/inc/lib/ezpdf/class.ezpdf.php', + __DIR__.'/../../../../main/inc/lib/current_user.class.php', + __DIR__.'/../../../../main/inc/lib/current_course.class.php', + __DIR__.'/../../../../main/inc/lib/response.class.php', + __DIR__.'/../../../../main/inc/lib/result_set.class.php', + __DIR__.'/../../../../main/inc/lib/session_handler.class.php', + __DIR__.'/../../../../main/exercice/testcategory.class.php', + __DIR__.'/../../../../main/inc/lib/WCAG/WCAG_rendering.php', + __DIR__.'/../../../../main/inc/lib/zip.class.php', + __DIR__.'/../../../../main/inc/lib/student_publication.class.php', + __DIR__.'/../../../../main/inc/lib/ajax_controller.class.php', + __DIR__.'/../../../../main/inc/lib/system/closure_compiler.class.php', + __DIR__.'/../../../../main/inc/lib/system/code_utilities.class.php', + __DIR__.'/../../../../main/inc/lib/controller.class.php', + __DIR__.'/../../../../main/inc/lib/system/text/converter.class.php', + __DIR__.'/../../../../main/inc/lib/course_entity_repository.class.php', + __DIR__.'/../../../../main/inc/lib/course_entity.class.php', + __DIR__.'/../../../../main/inc/lib/cache.class.php', + __DIR__.'/../../../../main/inc/lib/system/web/request_server.class.php', + __DIR__.'/../../../../main/inc/lib/system/session.class.php', + __DIR__.'/../../../../main/inc/lib/page.class.php', + __DIR__.'/../../../../main/inc/lib/mail.lib.inc.php', + __DIR__.'/../../../../main/admin/system_management.php', + + ]; + + foreach ($paths as $path) { + if (is_dir($path) && is_writable($path)) { + self::rmdirr($path); + } } + + $fs = new Filesystem(); + $fs->remove($files); } private static function rmdirr($dirname, $delete_only_content_in_folder = false, $strict = false) diff --git a/src/Chamilo/CoreBundle/DoctrineExtensions/DBAL/Types/UTCDateTimeType.php b/src/Chamilo/CoreBundle/DoctrineExtensions/DBAL/Types/UTCDateTimeType.php index 3c03e72ea7..fcde01a641 100644 --- a/src/Chamilo/CoreBundle/DoctrineExtensions/DBAL/Types/UTCDateTimeType.php +++ b/src/Chamilo/CoreBundle/DoctrineExtensions/DBAL/Types/UTCDateTimeType.php @@ -1,4 +1,5 @@ format($platform->getDateTimeFormatString()); } + /** + * {@inheritdoc} + */ public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { diff --git a/tests/main/inc/lib/main_api.lib.test.php b/tests/main/inc/lib/main_api.lib.test.php index 4a5907b7b7..ff900a334a 100755 --- a/tests/main/inc/lib/main_api.lib.test.php +++ b/tests/main/inc/lib/main_api.lib.test.php @@ -139,14 +139,6 @@ class TestMainApi extends UnitTestCase { $this->assertTrue($res); ob_end_clean(); } - - function testApiSessionStart(){ - if (!headers_sent()) { - $res = Chamilo::session()->start($already_sintalled=true); - } - $this->assertTrue(is_null($res)); - } - // function testApiSessionRegister(){ // $$variable[session_register]=false; // global $$variable;