Fix installation

pull/3346/head
Julio Montoya 5 years ago
parent 0383a8a834
commit 182fa29275
  1. 39
      public/main/inc/lib/api.lib.php
  2. 39
      public/main/inc/lib/usermanager.lib.php
  3. 70
      public/main/install/install.lib.php
  4. 97
      src/CoreBundle/Entity/Listener/ResourceListener.php
  5. 70
      src/CoreBundle/Entity/Listener/ResourceNodeListener.php

@ -1695,7 +1695,10 @@ function api_get_user_info_from_entity(
$result['creator_id'] = $user->getCreatorId();
$result['registration_date'] = $user->getRegistrationDate()->format('Y-m-d H:i:s');
$result['hr_dept_id'] = $user->getHrDeptId();
$result['expiration_date'] = $user->getExpirationDate()->format('Y-m-d H:i:s');
$result['expiration_date'] = '';
if ($user->getExpirationDate()) {
$result['expiration_date'] = $user->getExpirationDate()->format('Y-m-d H:i:s');
}
$result['last_login'] = null;
if ($user->getLastLogin()) {
@ -2913,38 +2916,6 @@ function api_get_setting($variable)
return $settingsManager->getSetting($variable);
break;
}
global $_setting;
/*if ($variable == 'header_extra_content') {
$filename = api_get_home_path().'header_extra_content.txt';
if (file_exists($filename)) {
$value = file_get_contents($filename);
return $value;
} else {
return '';
}
}
if ($variable == 'footer_extra_content') {
$filename = api_get_home_path().'footer_extra_content.txt';
if (file_exists($filename)) {
$value = file_get_contents($filename);
return $value;
} else {
return '';
}
}*/
$value = null;
if (is_null($key)) {
$value = ((isset($_setting[$variable]) && '' != $_setting[$variable]) ? $_setting[$variable] : null);
} else {
if (isset($_setting[$variable][$key])) {
$value = $_setting[$variable][$key];
}
}
return $value;
}
/**
@ -3881,7 +3852,7 @@ function api_not_allowed(
$message = null,
$responseCode = 0
) {
//throw new Exception('You are not allowed');
throw new Exception('You are not allowed');
}
/**

@ -183,7 +183,8 @@ class UserManager
$creatorId = 0,
$emailTemplate = [],
$redirectToURLAfterLogin = '',
$addUserToNode = true
$addUserToNode = true,
$addUserToUrl = true
) {
$authSource = !empty($authSource) ? $authSource : PLATFORM_AUTH_SOURCE;
$creatorId = empty($creatorId) ? api_get_user_id() : 0;
@ -278,33 +279,31 @@ class UserManager
$password = $authSource;
}
// database table definition
$table_user = Database::get_main_table(TABLE_MAIN_USER);
// Checking the user language
$languages = api_get_languages();
$language = strtolower($language);
if (isset($languages)) {
if (!in_array($language, $languages)) {
$language = api_get_setting('platformLanguage');
}
// Default to english
if (!in_array($language, $languages)) {
$language = 'en';
}
$currentDate = api_get_utc_datetime();
$now = new DateTime();
if (empty($expirationDate) || '0000-00-00 00:00:00' == $expirationDate) {
if (empty($expirationDate) || '0000-00-00 00:00:00' === $expirationDate) {
$expirationDate = null;
// Default expiration date
// if there is a default duration of a valid account then
// we have to change the expiration_date accordingly
// Accept 0000-00-00 00:00:00 as a null value to avoid issues with
// third party code using this method with the previous (pre-1.10)
// value of 0000...
if ('' != api_get_setting('account_valid_duration')) {
/*if ('' != api_get_setting('account_valid_duration')) {
$expirationDate = new DateTime($currentDate);
$days = (int) api_get_setting('account_valid_duration');
$expirationDate->modify('+'.$days.' day');
}
}*/
} else {
$expirationDate = api_get_utc_datetime($expirationDate);
$expirationDate = new \DateTime($expirationDate, new DateTimeZone('UTC'));
@ -319,7 +318,6 @@ class UserManager
->setPlainPassword($password)
->setEmail($email)
->setOfficialCode($official_code)
//->setPictureUri($picture_uri)
->setCreatorId($creatorId)
->setAuthSource($authSource)
->setPhone($phone)
@ -339,8 +337,6 @@ class UserManager
$em = Database::getManager();
$repo = Container::$container->get('Chamilo\CoreBundle\Repository\UserRepository');
$repo->updateUser($user, false);
/*$factory = Container::$container->get('Chamilo\CoreBundle\Repository\ResourceFactory');
$repo = $factory->createRepository('global', 'users');*/
// Add user as a node
if ($addUserToNode) {
@ -349,7 +345,6 @@ class UserManager
->setTitle($loginName)
->setCreator(api_get_user_entity($creatorId))
->setResourceType($repo->getResourceType())
// ->setParent($url->getResourceNode())
;
$em->persist($resourceNode);
$user->setResourceNode($resourceNode);
@ -367,7 +362,7 @@ class UserManager
DRH => 'RRHH',
SESSIONADMIN => 'SESSION_ADMIN',
STUDENT_BOSS => 'STUDENT_BOSS',
INVITEE => 'INVITEE'
INVITEE => 'INVITEE',
];
if (isset($statusToGroup[$status])) {
@ -385,11 +380,13 @@ class UserManager
self::add_user_as_admin($user);
}
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($userId, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($userId, 1);
if ($addUserToUrl) {
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($userId, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($userId, 1);
}
}
if (is_array($extra) && count($extra) > 0) {

@ -5,13 +5,14 @@ use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\BranchSync;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\Group;
use Chamilo\CoreBundle\Entity\TicketCategory as TicketCategory;
use Chamilo\CoreBundle\Entity\TicketPriority as TicketPriority;
use Chamilo\CoreBundle\Entity\TicketProject as TicketProject;
use Chamilo\CoreBundle\Entity\TicketCategory;
use Chamilo\CoreBundle\Entity\TicketPriority;
use Chamilo\CoreBundle\Entity\TicketProject;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\ToolChain;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
/**
* Chamilo LMS
@ -22,7 +23,6 @@ use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
* of older versions before upgrading.
*/
/* CONSTANTS */
define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
/**
@ -88,19 +88,18 @@ function checkExtension(
} else {
if ($optional) {
return Display::label(get_lang('Extension installed but not enabled'), 'warning');
} else {
return Display::label(get_lang('Extension installed but not enabled'), 'important');
}
return Display::label(get_lang('Extension installed but not enabled'), 'important');
}
} else {
return Display::label($returnSuccess, 'success');
}
return Display::label($returnSuccess, 'success');
} else {
if ($optional) {
return Display::label($returnFailure, 'warning');
} else {
return Display::label($returnFailure, 'important');
}
return Display::label($returnFailure, 'important');
}
}
@ -125,11 +124,12 @@ function checkPhpSetting(
$currentPhpValue = getPhpSetting($phpSetting);
if ($currentPhpValue == $recommendedValue) {
return Display::label($currentPhpValue.' '.$returnSuccess, 'success');
} else {
return Display::label($currentPhpValue.' '.$returnSuccess, 'important');
}
return Display::label($currentPhpValue.' '.$returnSuccess, 'important');
}
/**
* This function return the value of a php.ini setting if not "" or if exists,
* otherwise return false.
@ -140,7 +140,7 @@ function checkPhpSetting(
*/
function checkPhpSettingExists($phpSetting)
{
if ("" != ini_get($phpSetting)) {
if ('' != ini_get($phpSetting)) {
return ini_get($phpSetting);
}
@ -1634,7 +1634,13 @@ function display_configuration_settings_form(
// Parameter 2: administrator's password
if ('update' != $installType) {
$html .= display_configuration_parameter($installType, get_lang('Administrator password (<font color="red">you may want to change this</font>)'), 'passForm', $passForm, false);
$html .= display_configuration_parameter(
$installType,
get_lang('Administrator password (<font color="red">you may want to change this</font>)'),
'passForm',
$passForm,
false
);
}
// Parameters 3 and 4: administrator's names
@ -3035,6 +3041,7 @@ function installSchemas($container, $manager, $upgrade = false)
->setUrl('http://localhost/')
->setDescription('')
->setActive(1)
->setCreatedBy(1)
;
$em->persist($accessUrl);
$em->flush();
@ -3238,8 +3245,7 @@ function finishInstallationWithContainer(
}
installGroups($container, $manager);
installSchemas($container, $manager, false);
installPages($container);
error_log('Inserting data.sql');
// Inserting default data
@ -3278,9 +3284,9 @@ function finishInstallationWithContainer(
0,
[],
'',
false,
false
);
error_log('user creation - anon');
// Create anonymous user.
$anonId = UserManager::create_user(
@ -3308,13 +3314,33 @@ function finishInstallationWithContainer(
$adminId,
[],
'',
false,
false
);
error_log('Adding access url as a node');
$userManager = $container->get('Chamilo\CoreBundle\Repository\UserRepository');
$urlRepo = $container->get('Chamilo\CoreBundle\Repository\AccessUrlRepository');
$admin = $userManager->find($adminId);
// Login as admin
$token = new UsernamePasswordToken(
$admin,
$admin->getPassword(),
"public",
$admin->getRoles()
);
$container->get('security.token_storage')->setToken($token);
/*$event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent(
$container->get('request_stack'), $token
);
$container->get('event_dispatcher')->dispatch('security.interactive_login', $event);*/
installSchemas($container, $manager, false);
error_log('Adding access url as a node');
$accessUrl = $urlRepo->find(1);
$branch = new BranchSync();
@ -3322,13 +3348,15 @@ function finishInstallationWithContainer(
$branch->setUrl($accessUrl);
$manager->persist($branch);
$admin = $userManager->find($adminId);
$userManager->addUserToResourceNode($adminId, $adminId);
$userManager->addUserToResourceNode($anonId, $adminId);
$urlRepo->addResourceNode($accessUrl, $admin);
UrlManager::add_user_to_url($adminId, 1);
UrlManager::add_user_to_url($anonId, 1);
$manager->flush();
// Set default language
@ -3354,7 +3382,7 @@ function finishInstallationWithContainer(
lockSettings();
updateDirAndFilesPermissions();
fixMedia($container);
//fixMedia($container);
}
/**

@ -14,6 +14,7 @@ use Chamilo\CoreBundle\Entity\ResourceWithUrlInterface;
use Chamilo\CoreBundle\ToolChain;
use Cocur\Slugify\SlugifyInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -32,8 +33,12 @@ class ResourceListener
/**
* ResourceListener constructor.
*/
public function __construct(SlugifyInterface $slugify, ToolChain $toolChain, RequestStack $request, Security $security)
{
public function __construct(
SlugifyInterface $slugify,
ToolChain $toolChain,
RequestStack $request,
Security $security
) {
$this->slugify = $slugify;
$this->security = $security;
$this->toolChain = $toolChain;
@ -71,9 +76,10 @@ class ResourceListener
return $this->accessUrl;
}
public function prePersist(AbstractResource $resource, LifecycleEventArgs $args)
public function prePersist(AbstractResource $resource, LifecycleEventArgs $event)
{
$em = $args->getEntityManager();
error_log('resource listener prePersist');
$em = $event->getEntityManager();
$request = $this->request;
$url = null;
@ -101,23 +107,26 @@ class ResourceListener
}
$resourceNode = new ResourceNode();
$resource->setResourceNode($resourceNode);
$this->updateResourceName($resource);
$resourceName = $resource->getResourceName();
/*$resourceName = $resource->getResourceName();
if (empty($resourceName)) {
throw new \InvalidArgumentException('Resource needs a name');
}
}*/
$extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION));
/*$extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION));
if (empty($extension)) {
$slug = $this->slugify->slugify($resourceName);
} else {
$originalExtension = pathinfo($resourceName, PATHINFO_EXTENSION);
$originalBasename = \basename($resourceName, $originalExtension);
$slug = sprintf('%s.%s', $this->slugify->slugify($originalBasename), $originalExtension);
}
}*/
$repo = $em->getRepository('ChamiloCoreBundle:ResourceType');
$class = str_replace('Entity', 'Repository', get_class($args->getEntity()));
$class = str_replace('Entity', 'Repository', get_class($event->getEntity()));
$class .= 'Repository';
$name = $this->toolChain->getResourceTypeNameFromRepository($class);
$resourceType = $repo->findOneBy(['name' => $name]);
@ -127,8 +136,6 @@ class ResourceListener
}
$resourceNode
->setTitle($resourceName)
->setSlug($slug)
->setCreator($creator)
->setResourceType($resourceType)
;
@ -151,7 +158,7 @@ class ResourceListener
$uploadedFile = $request->getCurrentRequest()->files->get('uploadFile');
if (empty($uploadedFile)) {
$content = $request->getCurrentRequest()->get('content');
$content = $request->getCurrentRequest()->get('contentFile');
$title = $resourceName.'.html';
$handle = tmpfile();
fwrite($handle, $content);
@ -217,12 +224,32 @@ class ResourceListener
return $resourceNode;
}
public function onFlush(AbstractResource $resource, OnFlushEventArgs $args)
{
error_log('onFlush');
}
/**
* When updating a Resource.
*/
public function preUpdate(AbstractResource $resource, PreUpdateEventArgs $event)
{
/*error_log('preUpdate');
error_log('resource listener preUpdate');
$em = $event->getEntityManager();
error_log('updateResourceName');
$this->updateResourceName($resource);
$resourceNode = $resource->getResourceNode();
$resourceNode->setTitle($resource->getResourceName());
error_log('inside');
//error_log($resource->getTitle());
error_log($resource->getResourceNode()->getTitle());
error_log($resource->getResourceNode()->getId());
$resource->setResourceNode($resourceNode);
$em->persist($resourceNode);
/*
error_log($fieldIdentifier);
$em = $event->getEntityManager();
if ($event->hasChangedField($fieldIdentifier)) {
@ -235,39 +262,37 @@ class ResourceListener
}*/
}
public function postUpdate(AbstractResource $resource, LifecycleEventArgs $args)
public function postUpdate(AbstractResource $resource, LifecycleEventArgs $event)
{
//error_log('postUpdate');
//$em = $args->getEntityManager();
//$em = $event->getEntityManager();
//$this->updateResourceName($resource, $resource->getResourceName(), $em);
}
public function updateResourceName(AbstractResource $resource, $newValue, $em)
public function updateResourceName(AbstractResource $resource)
{
// Updates resource node name with the resource name.
/*$resourceNode = $resource->getResourceNode();
$newName = $resource->getResourceName();
$resourceName = $resource->getResourceName();
$resourceNode = $resource->getResourceNode();
$name = $resourceNode->getSlug();
if (empty($resourceName)) {
throw new \InvalidArgumentException('Resource needs a name');
}
if ($resourceNode->hasResourceFile()) {
$originalExtension = pathinfo($name, PATHINFO_EXTENSION);
$originalBasename = \basename($name, $originalExtension);
$modified = sprintf('%s.%s', $this->slugify->slugify($originalBasename), $originalExtension);
$extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION));
if (empty($extension)) {
$slug = $this->slugify->slugify($resourceName);
} else {
$modified = $this->slugify->slugify($name);
$originalExtension = pathinfo($resourceName, PATHINFO_EXTENSION);
$originalBasename = \basename($resourceName, $originalExtension);
$slug = sprintf('%s.%s', $this->slugify->slugify($originalBasename), $originalExtension);
}
error_log( 'aaaa');
error_log($resourceName);
error_log($slug);
error_log($name);
error_log($modified);
$resourceNode->setSlug($modified);
if ($resourceNode->hasResourceFile()) {
$resourceNode->getResourceFile()->setOriginalName($name);
}
$em->persist($resourceNode);
$em->flush();*/
$resourceNode
->setTitle($resourceName)
// ->setSlug($slug)
;
}
}

@ -0,0 +1,70 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Listener;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\ResourceToCourseInterface;
use Chamilo\CoreBundle\Entity\ResourceToRootInterface;
use Chamilo\CoreBundle\Entity\ResourceWithUrlInterface;
use Chamilo\CoreBundle\ToolChain;
use Cocur\Slugify\SlugifyInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
/**
* Class ResourceNodeListener.
*/
class ResourceNodeListener
{
protected $slugify;
protected $request;
protected $accessUrl;
/**
* ResourceListener constructor.
*/
public function __construct(
SlugifyInterface $slugify,
ToolChain $toolChain,
RequestStack $request,
Security $security
) {
$this->slugify = $slugify;
$this->security = $security;
$this->toolChain = $toolChain;
$this->request = $request;
$this->accessUrl = null;
}
public function prePersist(ResourceNode $resourceNode, LifecycleEventArgs $event)
{
error_log('resource node prePersist');
return true;
}
/**
* When updating a Resource.
*/
public function preUpdate(ResourceNode $resourceNode, PreUpdateEventArgs $event)
{
error_log('resource node preUpdate');
return true;
}
public function postUpdate(ResourceNode $resourceNode, LifecycleEventArgs $event)
{
error_log('ResourceNode postUpdate');
}
}
Loading…
Cancel
Save