fix_restored_learnpaths.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. use Chamilo\CourseBundle\Entity\CLp;
  5. use Doctrine\ORM\Query\Expr\Join;
  6. use Chamilo\CourseBundle\Entity\CTool;
  7. require_once __DIR__.'/../../main/inc/global.inc.php';
  8. $em = Database::getManager();
  9. $qb1 = $em->createQueryBuilder();
  10. $result1 = $qb1
  11. ->select('lp')
  12. ->from('ChamiloCourseBundle:CLp', 'lp')
  13. ->innerJoin('ChamiloCourseBundle:CTool', 't', JOIN::WITH, 'lp.cId = t.cId AND lp.name = t.name')
  14. ->where(
  15. $qb1->expr()->eq('t.link', ':link')
  16. )
  17. ->setParameter('link', 'lp/lp_controller.php?action=view&lp_id=$new_lp_id&id_session=0')
  18. ->getQuery()
  19. ->getResult();
  20. /** @var CLp $lp */
  21. foreach ($result1 as $i => $lp) {
  22. echo ($i + 1)." LP {$lp->getId()}: {$lp->getName()}".PHP_EOL;
  23. $qb2 = $em->createQueryBuilder();
  24. /** @var CTool $tool */
  25. $tool = $qb2
  26. ->select('t')
  27. ->from('ChamiloCourseBundle:CTool', 't')
  28. ->where(
  29. $qb2->expr()->andX(
  30. $qb2->expr()->eq('t.link', ':link'),
  31. $qb2->expr()->eq('t.name', ':name'),
  32. $qb2->expr()->eq('t.cId', ':cid')
  33. )
  34. )
  35. ->setParameters([
  36. 'link' => 'lp/lp_controller.php?action=view&lp_id=$new_lp_id&id_session=0',
  37. 'name' => $lp->getName(),
  38. 'cid' => $lp->getCId()
  39. ])
  40. ->getQuery()
  41. ->getOneOrNullResult();
  42. $tool->setLink("lp/lp_controller.php?action=view&lp_id={$lp->getId()}&id_session=0");
  43. $em->persist($tool);
  44. $em->flush();
  45. echo "\tTool: {$tool->getId()}: {$tool->getName()}".PHP_EOL;
  46. echo "\tNew link: {$tool->getLink()}".PHP_EOL;
  47. }