src/Controller/DefaultController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Mime\Address;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Pimcore\Model\DataObject\ProductCategory;
  10. use Pimcore\Db;
  11. use Pimcore\Model\DataObject\Service as DataObjectService;
  12. use Symfony\Component\Process\Process;
  13. use Pimcore\Model\Asset;
  14. use Pimcore\Model\User;
  15. use Pimcore\Model\DataObject\Product;
  16. use Pimcore\Tool\Console;
  17. use Pimcore\Mail;
  18. use Symfony\Component\Workflow\Registry;
  19. use Pimcore\Workflow\WorkflowManager;
  20. use Pimcore\Workflow\Manager;
  21. use App\Service\WorkflowService;
  22. class DefaultController extends FrontendController
  23. {
  24.     /**
  25.      * @Template
  26.      * @param Request $request
  27.      * @return array
  28.      */
  29.     public function defaultAction(Request $request)
  30.     {
  31.         return [];
  32.     }
  33.     
  34.     
  35.     /**
  36.      * @Route("/test123", name="test", methods={"GET"})
  37.      */
  38.     public function executeImportData1(Registry $workflowRegistry)
  39.     {
  40.         $product Product::getById(1579);
  41.         $currentPlace WorkflowService::getCurrentPlace(1579);
  42.         $workflow $workflowRegistry->get($product'workflow');
  43.         // dd($workflow);
  44.         // $workflow = $workflowRegistry->getEnabledTransitions($product);
  45.         // $transitions = $this->definition->getTransitions();
  46.         // $marking = $workflow->getMarking($product);
  47.         // $transitionBlockerList = $workflow->buildTransitionBlockerListForTransition($subject, $marking, $transition);
  48.         // dd($transitionBlockerList);
  49.         
  50.         // dd($workflow->getEnabledTransitions($product));
  51.         // dd($workflow, $workflow->getMarking($product));
  52.         // dd($workflow->can($product, 'update_marketing_review_marketing'), $currentPlace);
  53.         // dd($workflow->apply($product, 'update_marketing_review_marketing'), $currentPlace);
  54.         dd($workflow->apply($product'update_marketing_2_review_marketing_2'), $currentPlace);
  55.         $currentPlace WorkflowService::getCurrentPlace(1578);
  56.         dd($currentPlace);
  57.         $workflow $workflowRegistry->get($product'workflow');
  58.         dd(get_class_methods($workflow), $workflow->getDefinition(), $workflow);
  59.         $product Product::getById(1578);
  60.         dd(get_class_methods($product));
  61.         die;
  62.         $product Product::getById(1578);
  63.         $workflow $workflowRegistry->get($product'workflow');
  64.         dd(get_class_methods($workflow), $workflow);
  65.         dd(get_class_methods($product));
  66.         die;
  67.         $user User::getById(17);
  68.         dd(get_class_methods($user), $user->getRoles());
  69.         $mail = new \Pimcore\Mail([
  70.             'document' => "/Email/workflow_transition"
  71.             // 'params' => $this->getNotificationEmailParameters('Product', $subject, $workflow, $action, $deeplink, $language)
  72.         ]);
  73.         $mail->addTo($user->getEmail(), $user->getName());
  74.         // $mail->from(new Address('contact@softmaster.vn', 'digicore'));
  75.         $result $mail->send();
  76.         dd($result);
  77.         // die;
  78.         $mail = new Mail();
  79.         $mail->to('nvtrong1615@gmail.com');
  80.         $mail->setDocument('/Email/workflow_transition');
  81.         // $mail->setParams(['code' => 'trongnnc hahah']);
  82.         // $mail->from('support@softmaster.vn');
  83.         $mail->from(new Address('contact@softmaster.vn''digicore'));
  84.         $mail->getHeaders()->addTextHeader('X-Transport''main');
  85.         $result $mail->send();
  86.         dd($result);
  87.         $video Asset\Video::getById(544);
  88.         $asset \Pimcore\Model\Asset::getById(474); // Replace with actual asset ID
  89.         if ($asset) {
  90.             echo "Asset Type: " $asset->getType(); // Should return 'document', 'image', etc.
  91.         }
  92.         die(12);
  93.         phpinfo();
  94.         die;
  95.         $cmd = [
  96.             => "/usr/bin/soffice",
  97.             => "--headless",
  98.             => "--nologo",
  99.             => "--nofirststartwizard",
  100.             => "-env:UserInstallation=file:///var/www/html/var/tmp/libreoffice",
  101.             => "--norestore",
  102.             => "--convert-to",
  103.             => "pdf:writer_web_pdf_Export",
  104.             => "--outdir",
  105.             => "/var/www/html/var/tmp",
  106.             10 => "/var/www/html/public/var/assets/test/4. IDEA CDS - Huong dan su dung Danh cho Quan tri he thong.docx"
  107.         ];
  108.         Console::addLowProcessPriority($cmd);
  109.         $process = new Process($cmd);
  110.         $process->setTimeout(240);
  111.         $data $process->start();
  112.         dd($data$process);
  113.         
  114.         phpinfo();
  115.         die;
  116.         $list = new ProductCategory\Listing();
  117.         dd($list->count());
  118.         dd(123);
  119.     }
  120.     /**
  121.      * @Route("/data-importer/run/parallel", name="importer-run-parallel", methods={"GET"})
  122.      */
  123.     public function executeImportData()
  124.     {
  125.         $result exec("cd ..&& bin/console  datahub:data-importer:process-queue-parallel"$output);
  126.         foreach ($output as $key => $val) {
  127.         }
  128.         echo $result;
  129.         die;
  130.     }
  131.     /**
  132.      * @Route("/restore-data", name="restore-data", methods={"GET"})
  133.      */
  134.     public function restoreData()
  135.     {
  136.         $db Db::get();
  137.         
  138.         // Get list objects tbl
  139.         $queryGetListObjects "SELECT * FROM objects WHERE o_path LIKE '%Phả hệ sản phẩm%'";
  140.         $queryFetch $db->fetchAll($queryGetListObjects);
  141.         if(!empty($queryFetch)){
  142.             foreach($queryFetch as $val){
  143.                 $class "Pimcore\Model\DataObject\\" ucfirst('ProductCategory');
  144.                 $object = new $class;
  145.                 $path str_replace("/Phả hệ sản phẩm/","/Phả hệ sản phẩm v2/",  $val['o_path']);
  146.                 DataObjectService::createFolderByPath($path);
  147.                 $object->setKey(\Pimcore\Model\Element\Service::getValidKey($val['o_key'], 'object'));
  148.                 $pathArr = (explode('/'$path));
  149.                 $parentObj '';
  150.                 if(count($pathArr) >= 4){
  151.                     if ($pathArr[count($pathArr) - 2] && $pathArr[count($pathArr) - 2] != $val['o_key']) {
  152.                         $parentName array_reverse($pathArr)[1];
  153.                         if($parentName){
  154.                             $parentList = new ProductCategory\Listing();
  155.                             $parentList->addConditionParam("categoryName = '{$parentName}'");
  156.                             $parentList->addConditionParam("o_path LIKE '%Phả hệ sản phẩm v2%'");
  157.                             $parentObj $parentList->current();
  158.                         }
  159.                     }
  160.                     
  161.                     if (!empty($parentObj)) {
  162.                         $object->setParentCategory($parentObj);
  163.                     }
  164.                 }
  165.                 $object->setParent(\Pimcore\Model\DataObject::getByPath($path));
  166.                 $object->setCategoryCode($val['o_key']);
  167.                 $object->setCategoryName($val['o_key']);
  168.                 $object->setPublished(true);
  169.                 $object->save();
  170.             }
  171.         }
  172.         die();
  173.     }
  174. }