浏览代码

Add script to fix restored learnpaths - refs BT#13455

Angel Fernando Quiroz Campos 7 年之前
父节点
当前提交
16a139ead1
共有 1 个文件被更改,包括 58 次插入0 次删除
  1. 58 0
      tests/scripts/fix_restored_learnpaths.php

+ 58 - 0
tests/scripts/fix_restored_learnpaths.php

@@ -0,0 +1,58 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+//exit;
+
+use Chamilo\CourseBundle\Entity\CLp;
+use Doctrine\ORM\Query\Expr\Join;
+use Chamilo\CourseBundle\Entity\CTool;
+
+require_once __DIR__.'/../../main/inc/global.inc.php';
+
+$em = Database::getManager();
+
+$qb1 = $em->createQueryBuilder();
+$result1 = $qb1
+    ->select('lp')
+    ->from('ChamiloCourseBundle:CLp', 'lp')
+    ->innerJoin('ChamiloCourseBundle:CTool', 't', JOIN::WITH, 'lp.cId = t.cId AND lp.name = t.name')
+    ->where(
+        $qb1->expr()->eq('t.link', ':link')
+    )
+    ->setParameter('link', 'lp/lp_controller.php?action=view&lp_id=$new_lp_id&id_session=0')
+    ->getQuery()
+    ->getResult();
+
+/** @var CLp $lp */
+foreach ($result1 as $i => $lp) {
+    echo ($i + 1)." LP {$lp->getId()}: {$lp->getName()}".PHP_EOL;
+
+    $qb2 = $em->createQueryBuilder();
+
+    /** @var CTool $tool */
+    $tool = $qb2
+        ->select('t')
+        ->from('ChamiloCourseBundle:CTool', 't')
+        ->where(
+            $qb2->expr()->andX(
+                $qb2->expr()->eq('t.link', ':link'),
+                $qb2->expr()->eq('t.name', ':name'),
+                $qb2->expr()->eq('t.cId', ':cid')
+            )
+        )
+        ->setParameters([
+            'link' => 'lp/lp_controller.php?action=view&lp_id=$new_lp_id&id_session=0',
+            'name' => $lp->getName(),
+            'cid' => $lp->getCId()
+        ])
+        ->getQuery()
+        ->getOneOrNullResult();
+
+    $tool->setLink("lp/lp_controller.php?action=view&lp_id={$lp->getId()}&id_session=0");
+
+    $em->persist($tool);
+    $em->flush();
+
+    echo "\tTool: {$tool->getId()}: {$tool->getName()}".PHP_EOL;
+    echo "\tNew link: {$tool->getLink()}".PHP_EOL;
+}