Remove unused code, refactor code.

pull/3064/head
Julio 5 years ago
parent 2f6a4a7176
commit 4e96534806
  1. 17
      psalm.xml
  2. 15
      src/ContactBundle/Controller/ContactController.php
  3. 12
      src/CourseBundle/Component/CourseCopy/CourseBuilder.php
  4. 20
      src/CourseBundle/Component/CourseCopy/CourseRestorer.php
  5. 2
      src/CourseBundle/Repository/CAnnouncementRepository.php
  6. 2
      src/SettingsBundle/Manager/SettingsManager.php
  7. 1
      src/ThemeBundle/Controller/ExceptionController.php
  8. 2
      src/ThemeBundle/Event/MessageListEvent.php
  9. 2
      src/ThemeBundle/Event/NotificationListEvent.php
  10. 2
      src/ThemeBundle/Event/TaskListEvent.php
  11. 2
      src/ThemeBundle/EventListener/TwigListener.php
  12. 2
      src/ThemeBundle/Model/MenuItemModel.php
  13. 11
      src/ThemeBundle/Theme/ThemeManager.php
  14. 11
      src/UserBundle/Entity/User.php
  15. 15
      src/UserBundle/Repository/UserRepository.php

@ -12,7 +12,6 @@
<directory name="vendor" /> <directory name="vendor" />
<directory name="src/AdminBundle" /> <directory name="src/AdminBundle" />
<directory name="src/ClassificationBundle" /> <directory name="src/ClassificationBundle" />
<directory name="src/ContactBundle" />
<!-- <directory name="src/CoreBundle" />--> <!-- <directory name="src/CoreBundle" />-->
<directory name="src/CoreBundle/Migrations" /> <directory name="src/CoreBundle/Migrations" />
<directory name="src/CoreBundle/Component/Editor" /> <directory name="src/CoreBundle/Component/Editor" />
@ -20,15 +19,15 @@
<directory name="src/FaqBundle" /> <directory name="src/FaqBundle" />
<directory name="src/GraphQlBundle" /> <directory name="src/GraphQlBundle" />
<directory name="src/LtiBundle" /> <directory name="src/LtiBundle" />
<directory name="src/MediaBundle" /> <!-- <directory name="src/MediaBundle" />-->
<directory name="src/NotificationBundle" /> <!-- <directory name="src/NotificationBundle" />-->
<directory name="src/PageBundle" /> <!-- <directory name="src/PageBundle" />-->
<directory name="src/SettingsBundle" /> <!-- <directory name="src/SettingsBundle" />-->
<directory name="src/SkillBundle" /> <directory name="src/SkillBundle" />
<directory name="src/ThemeBundle" /> <!-- <directory name="src/ThemeBundle" />-->
<directory name="src/TicketBundle" /> <!-- <directory name="src/TicketBundle" />-->
<directory name="src/TimelineBundle" /> <!-- <directory name="src/TimelineBundle" />-->
<directory name="src/UserBundle" /> <!-- <directory name="src/UserBundle" />-->
</ignoreFiles> </ignoreFiles>
</projectFiles> </projectFiles>

@ -9,6 +9,8 @@ use Chamilo\ContactBundle\Form\Type\ContactType;
use Chamilo\UserBundle\Entity\User; use Chamilo\UserBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
/** /**
@ -21,7 +23,7 @@ class ContactController extends AbstractController
/** /**
* @Route("/", name="contact") * @Route("/", name="contact")
*/ */
public function indexAction(Request $request) public function indexAction(Request $request, MailerInterface $mailer)
{ {
/** @var User $user */ /** @var User $user */
$user = $this->getUser(); $user = $this->getUser();
@ -47,10 +49,10 @@ class ContactController extends AbstractController
$category = $em->getRepository('ChamiloContactBundle:Category')->find($category); $category = $em->getRepository('ChamiloContactBundle:Category')->find($category);
if ($form->isValid()) { if ($form->isValid()) {
$message = \Swift_Message::newInstance() $message = new Email();
->setSubject($form->get('subject')->getData()) $message->subject($form->get('subject')->getData())
->setFrom($form->get('email')->getData()) ->from($form->get('email')->getData())
->setTo($category->getEmail()) ->to($category->getEmail())
->setBody( ->setBody(
$this->renderView( $this->renderView(
'@ChamiloContact/contact.html.twig', '@ChamiloContact/contact.html.twig',
@ -65,7 +67,8 @@ class ContactController extends AbstractController
) )
); );
$this->get('mailer')->send($message); $mailer->send($message);
$this->addFlash( $this->addFlash(
'success', 'success',
$this->get('translator')->trans('Your email has been sent! Thanks!') $this->get('translator')->trans('Your email has been sent! Thanks!')

@ -589,8 +589,8 @@ class CourseBuilder
$courseId = (int) $courseId; $courseId = (int) $courseId;
$sql = "SELECT * FROM $table WHERE c_id = $courseId "; $sql = "SELECT * FROM $table WHERE c_id = $courseId ";
if (!empty($thread_id) && !empty($forum_id)) { if (!empty($thread_id) && !empty($forum_id)) {
$forum_id = intval($forum_id); $forum_id = (int) $forum_id;
$thread_id = intval($thread_id); $thread_id = (int) $thread_id;
$sql .= " AND thread_id = $thread_id AND forum_id = $forum_id "; $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
} }
@ -1349,7 +1349,7 @@ class CourseBuilder
$courseId = (int) $courseId; $courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) { if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id); $session_id = (int) $session_id;
if ($withBaseContent) { if ($withBaseContent) {
$sessionCondition = api_get_session_condition( $sessionCondition = api_get_session_condition(
$session_id, $session_id,
@ -1573,7 +1573,7 @@ class CourseBuilder
$courseId = (int) $courseId; $courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) { if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id); $session_id = (int) $session_id;
if ($withBaseContent) { if ($withBaseContent) {
$sessionCondition = api_get_session_condition( $sessionCondition = api_get_session_condition(
$session_id, $session_id,
@ -1670,7 +1670,7 @@ class CourseBuilder
$courseId = (int) $courseId; $courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) { if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id); $session_id = (int) $session_id;
if ($withBaseContent) { if ($withBaseContent) {
$sessionCondition = api_get_session_condition( $sessionCondition = api_get_session_condition(
$session_id, $session_id,
@ -1728,7 +1728,7 @@ class CourseBuilder
$courseId = (int) $courseId; $courseId = (int) $courseId;
$courseInfo = api_get_course_info_by_id($courseId); $courseInfo = api_get_course_info_by_id($courseId);
$session_id = intval($session_id); $session_id = (int) $session_id;
if ($withBaseContent) { if ($withBaseContent) {
$sessionCondition = api_get_session_condition( $sessionCondition = api_get_session_condition(
$session_id, $session_id,

@ -878,7 +878,7 @@ class CourseRestorer
if (is_file($this->course->backup_path.'/'.$document->path) && if (is_file($this->course->backup_path.'/'.$document->path) &&
is_readable($this->course->backup_path.'/'.$document->path) && is_readable($this->course->backup_path.'/'.$document->path) &&
is_dir(dirname($path.$document->path)) && is_dir(dirname($path.$document->path)) &&
is_writeable(dirname($path.$document->path)) is_writable(dirname($path.$document->path))
) { ) {
copy( copy(
$this->course->backup_path.'/'.$document->path, $this->course->backup_path.'/'.$document->path,
@ -970,7 +970,7 @@ class CourseRestorer
dirname($path.$document->path).': destination directory not found' dirname($path.$document->path).': destination directory not found'
); );
} }
if (!is_writeable(dirname($path.$document->path))) { if (!is_writable(dirname($path.$document->path))) {
error_log( error_log(
'Course copy generated an ignorable error while trying to copy '. 'Course copy generated an ignorable error while trying to copy '.
$this->course->backup_path.'/'.$document->path.' to '. $this->course->backup_path.'/'.$document->path.' to '.
@ -1188,7 +1188,7 @@ class CourseRestorer
$this->course->backup_path, $this->course->backup_path,
$this->course->info['path'] $this->course->info['path']
); );
$params['session_id'] = intval($sessionId); $params['session_id'] = (int) $sessionId;
$params['cat_id'] = 0; $params['cat_id'] = 0;
unset($params['iid']); unset($params['iid']);
@ -1239,7 +1239,7 @@ class CourseRestorer
$params['thread_last_post'] = 0; $params['thread_last_post'] = 0;
$params['thread_replies'] = 0; $params['thread_replies'] = 0;
$params['thread_views'] = 0; $params['thread_views'] = 0;
$params['session_id'] = intval($sessionId); $params['session_id'] = (int) $sessionId;
$params['thread_id'] = 0; $params['thread_id'] = 0;
unset($params['iid']); unset($params['iid']);
@ -1348,7 +1348,7 @@ class CourseRestorer
FROM $link_table FROM $link_table
WHERE WHERE
c_id = ".$this->destination_course_id." AND c_id = ".$this->destination_course_id." AND
category_id='".intval($cat_id)."'"; category_id='".(int) $cat_id."'";
$result = Database::query($sql); $result = Database::query($sql);
list($max_order) = Database::fetch_array($result); list($max_order) = Database::fetch_array($result);
@ -3138,12 +3138,12 @@ class CourseRestorer
'reflink' => self::DBUTF8($wiki->reflink), 'reflink' => self::DBUTF8($wiki->reflink),
'title' => self::DBUTF8($wiki->title), 'title' => self::DBUTF8($wiki->title),
'content' => false === $wiki->content ? '' : self::DBUTF8($wiki->content), 'content' => false === $wiki->content ? '' : self::DBUTF8($wiki->content),
'user_id' => intval($wiki->user_id), 'user_id' => (int) ($wiki->user_id),
'group_id' => intval($wiki->group_id), 'group_id' => (int) ($wiki->group_id),
'dtime' => self::DBUTF8($wiki->dtime), 'dtime' => self::DBUTF8($wiki->dtime),
'progress' => self::DBUTF8($wiki->progress), 'progress' => self::DBUTF8($wiki->progress),
'version' => intval($wiki->version), 'version' => (int) ($wiki->version),
'session_id' => !empty($session_id) ? intval($session_id) : 0, 'session_id' => !empty($session_id) ? (int) $session_id : 0,
'addlock' => 0, 'addlock' => 0,
'editlock' => 0, 'editlock' => 0,
'visibility' => 0, 'visibility' => 0,
@ -3585,7 +3585,7 @@ class CourseRestorer
if (is_file($this->course->backup_path.'/'.$asset->path) && if (is_file($this->course->backup_path.'/'.$asset->path) &&
is_readable($this->course->backup_path.'/'.$asset->path) && is_readable($this->course->backup_path.'/'.$asset->path) &&
is_dir(dirname($path.$asset->path)) && is_dir(dirname($path.$asset->path)) &&
is_writeable(dirname($path.$asset->path)) is_writable(dirname($path.$asset->path))
) { ) {
switch ($this->file_option) { switch ($this->file_option) {
case FILE_SKIP: case FILE_SKIP:

@ -173,7 +173,7 @@ final class CAnnouncementRepository extends ResourceRepository
->createQuery($dql) ->createQuery($dql)
->setParameters($parameters); ->setParameters($parameters);
if (!is_null($start) && !is_null($limit)) { if (null !== $start && null !== $limit) {
$query $query
->setFirstResult($start) ->setFirstResult($start)
->setMaxResults($limit); ->setMaxResults($limit);

@ -9,7 +9,6 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\SettingsCurrent; use Chamilo\CoreBundle\Entity\SettingsCurrent;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
//use Sylius\Bundle\ResourceBundle\Controller\EventDispatcherInterface;
use Sylius\Bundle\SettingsBundle\Event\SettingsEvent; use Sylius\Bundle\SettingsBundle\Event\SettingsEvent;
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface; use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
use Sylius\Bundle\SettingsBundle\Model\Settings; use Sylius\Bundle\SettingsBundle\Model\Settings;
@ -18,6 +17,7 @@ use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilder; use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilder;
use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Exception\ValidatorException;

@ -6,6 +6,7 @@ namespace Chamilo\ThemeBundle\Controller;
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Templating\TemplateReference;
/** /**
* Class ExceptionController. * Class ExceptionController.

@ -58,6 +58,6 @@ class MessageListEvent extends ThemeEvent
*/ */
public function getTotal() public function getTotal()
{ {
return 0 == $this->totalMessages ? sizeof($this->messages) : $this->totalMessages; return 0 == $this->totalMessages ? count($this->messages) : $this->totalMessages;
} }
} }

@ -52,6 +52,6 @@ class NotificationListEvent extends ThemeEvent
*/ */
public function getTotal() public function getTotal()
{ {
return 0 == $this->total ? sizeof($this->notifications) : $this->total; return 0 == $this->total ? count($this->notifications) : $this->total;
} }
} }

@ -49,6 +49,6 @@ class TaskListEvent extends ThemeEvent
*/ */
public function getTotal() public function getTotal()
{ {
return 0 == $this->total ? sizeof($this->tasks) : $this->total; return 0 == $this->total ? count($this->tasks) : $this->total;
} }
} }

@ -170,7 +170,7 @@ class TwigListener implements EventSubscriberInterface
foreach ($courseRegions as $subRegion) { foreach ($courseRegions as $subRegion) {
if (!empty($courseInfo)) { if (!empty($courseInfo)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) { if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) {
/** @var Plugin $plugin */ /** @var \Plugin $plugin */
$plugin = $pluginInfo['obj']; $plugin = $pluginInfo['obj'];
$regionListContent[$subRegion][] = $plugin->renderRegion($subRegion); $regionListContent[$subRegion][] = $plugin->renderRegion($subRegion);
} }

@ -253,7 +253,7 @@ class MenuItemModel implements MenuItemInterface
*/ */
public function hasChildren() public function hasChildren()
{ {
return sizeof($this->children) > 0; return count($this->children) > 0;
} }
/** /**

@ -54,36 +54,33 @@ class ThemeManager implements ContainerAwareInterface
public function getScripts($location = 'bottom') public function getScripts($location = 'bottom')
{ {
$unsorted = []; /*$unsorted = [];
$srcList = []; $srcList = [];
foreach ($this->javascripts as $id => $scriptDefinition) { foreach ($this->javascripts as $id => $scriptDefinition) {
if ($scriptDefinition['location'] == $location) { if ($scriptDefinition['location'] == $location) {
$unsorted[$id] = $scriptDefinition; $unsorted[$id] = $scriptDefinition;
} }
} }
$queue = $this->getResolver()->register($unsorted)->resolveAll(); $queue = $this->getResolver()->register($unsorted)->resolveAll();
foreach ($queue as $def) { foreach ($queue as $def) {
$srcList[] = $def['src']; $srcList[] = $def['src'];
} }
return $srcList; return $srcList;*/
} }
public function getStyles() public function getStyles()
{ {
/*
$srcList = []; $srcList = [];
$queue = $this->getResolver()->register($this->stylesheets)->resolveAll(); $queue = $this->getResolver()->register($this->stylesheets)->resolveAll();
foreach ($queue as $def) { foreach ($queue as $def) {
$srcList[] = $def['src']; $srcList[] = $def['src'];
} }
return $srcList; return $srcList;*/
} }
/**
* @return DependencyResolverInterface
*/
protected function getResolver() protected function getResolver()
{ {
$class = $this->resolverClass; $class = $this->resolverClass;

@ -1872,17 +1872,6 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement
return true; return true;
} }
public function getPictureLegacy(): string
{
$id = $this->id;
$uri = $this->getPictureUri();
if ($uri) {
return 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'.'small_'.$uri;
}
return '';
}
/** /**
* Get sentMessages. * Get sentMessages.
* *

@ -460,9 +460,9 @@ class UserRepository extends ResourceRepository
return $qb return $qb
->select('COUNT(a)') ->select('COUNT(a)')
->innerJoin('a.portals', 'u') ->innerJoin('a.portals', 'u')
->where('u.portal = :u and u.group = :g') ->where('u.portal = :u')
->andWhere($qb->expr()->in('a.roles', ['ROLE_TEACHER'])) ->andWhere($qb->expr()->in('a.roles', ['ROLE_TEACHER']))
->setParameters(['u' => $url, 'g' => $group]) ->setParameters(['u' => $url])
->getQuery() ->getQuery()
->getSingleScalarResult() ->getSingleScalarResult()
; ;
@ -625,17 +625,6 @@ class UserRepository extends ResourceRepository
/** @var CourseRelUser $course */ /** @var CourseRelUser $course */
foreach ($courses as $course) { foreach ($courses as $course) {
$list[] = $course->getCourse()->getCode(); $list[] = $course->getCourse()->getCode();
$courseDir = api_get_path(SYS_COURSE_PATH).$course->getCourse()->getDirectory();
$documentDir = $courseDir.'/document/chat_files/';
if (is_dir($documentDir)) {
$fs = new Finder();
$fs->files()->in($documentDir);
foreach ($fs as $file) {
$chatFiles[] =
$course->getCourse()->getDirectory().'/document/chat_files/'.$file->getFilename().' - '.
get_lang('This content is not accessible to you directly because of course-related access rules. If you require access to that data, please contact the Data Privacy Officer as defined in our privacy terms.');
}
}
} }
$user->setCourses($list); $user->setCourses($list);

Loading…
Cancel
Save