Skip to content

Commit

Permalink
fix(chore): resolve problem in installation about lib and cleanup cod…
Browse files Browse the repository at this point in the history
…e again
  • Loading branch information
jorisdugue committed Sep 19, 2023
1 parent b1b1925 commit 1023e79
Show file tree
Hide file tree
Showing 36 changed files with 135 additions and 152 deletions.
1 change: 0 additions & 1 deletion Command/H5pBundleCleanUpFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class H5pBundleCleanUpFilesCommand extends Command
{

/**
* @var H5POptions $h5POptions
*/
Expand Down
7 changes: 3 additions & 4 deletions Command/H5pBundleIncludeAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private function includeAssets(bool $copy): void
{
//get dir of vendor H5P

$fromDir = $this->appKernel->getProjectDir()."/vendor/h5p/";
$fromDir = $this->appKernel->getProjectDir() . "/vendor/h5p/";
//call service
$toDir = $this->appKernel->getProjectDir().'/public/bundles/studith5p/h5p/';
$toDir = $this->appKernel->getProjectDir() . '/public/bundles/studith5p/h5p/';

$coreSubDir = "h5p-core/";
$coreDirs = ["fonts", "images", "js", "styles"];
Expand All @@ -57,7 +57,6 @@ private function includeAssets(bool $copy): void
$editorSubDir = "h5p-editor/";
$editorDirs = ["ckeditor", "images", "language", "libs", "scripts", "styles"];
$this->createFiles($fromDir, $toDir, $editorSubDir, $editorDirs, $copy);

}

private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
Expand All @@ -69,7 +68,7 @@ private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
$copy
? $this->recurseCopy($src, $dist)
: symlink($src, $dist);
}
}
}

private function recurseCopy($src, $dst)
Expand Down
2 changes: 0 additions & 2 deletions Controller/H5PAJAXController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

/**
* @Route("/h5p/ajax")
* @extends AbstractController
*/
class H5PAJAXController extends AbstractController
{
Expand Down Expand Up @@ -62,7 +61,6 @@ public function contentTypeCacheCallback(): JsonResponse

$output = ob_get_contents();
ob_end_clean();

return $this->json(json_decode($output, true));
}

Expand Down
11 changes: 6 additions & 5 deletions Controller/H5PController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Studit\H5PBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
Expand All @@ -20,7 +19,6 @@
*/
class H5PController extends AbstractController
{

protected $h5PIntegrations;
protected $libraryStorage;
protected $entityManager;
Expand Down Expand Up @@ -74,7 +72,8 @@ public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5PO
$h5pIntegration['contents'][$contentIdStr]['styles'] = $cssFilePaths;
}
return $this->render(
'@StuditH5P/show.html.twig', [
'@StuditH5P/show.html.twig',
[
'contentId' => $content->getId(),
'isFrame' => $content->getLibrary()->isFrame(),
'h5pIntegration' => $h5pIntegration,
Expand Down Expand Up @@ -127,11 +126,13 @@ private function handleRequest(Request $request, Content $content = null)
}
$h5pIntegration = $this->h5PIntegrations->getEditorIntegrationSettings($content ? $content->getId() : null);
return $this->render(
'@StuditH5P/edit.html.twig', [
'@StuditH5P/edit.html.twig',
[
'form' => $form->createView(),
'h5pIntegration' => $h5pIntegration,
'h5pCoreTranslations' => $this->h5PIntegrations->getTranslationFilePath()
]);
]
);
}

/**
Expand Down
20 changes: 8 additions & 12 deletions Controller/H5PInteractionController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Studit\H5PBundle\Controller;


use Doctrine\ORM\EntityManagerInterface;
use Exception;
use H5PCore;
Expand All @@ -27,7 +25,6 @@
*/
class H5PInteractionController extends AbstractController
{

protected $entityManager;
protected $resultService;
protected $serializer;
Expand All @@ -39,15 +36,14 @@ class H5PInteractionController extends AbstractController

public function __construct(
EntityManagerInterface $entityManager,
ResultService $resultService,
SerializerInterface $serializer,
Packages $packages,
H5POptions $options,
H5PIntegration $h5PIntegration,
H5PCore $h5PCore,
KernelInterface $kernel
)
{
ResultService $resultService,
SerializerInterface $serializer,
Packages $packages,
H5POptions $options,
H5PIntegration $h5PIntegration,
H5PCore $h5PCore,
KernelInterface $kernel
) {
$this->entityManager = $entityManager;
$this->resultService = $resultService;
$this->serializer = $serializer;
Expand Down
24 changes: 11 additions & 13 deletions Core/H5PIntegration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Studit\H5PBundle\Core;

use Doctrine\ORM\EntityManager;
Expand All @@ -15,7 +14,6 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;


class H5PIntegration extends H5PUtils
{
/**
Expand Down Expand Up @@ -63,16 +61,15 @@ class H5PIntegration extends H5PUtils
* @param \H5PContentValidator $contentValidator
*/
public function __construct(
\H5PCore $core,
H5POptions $options,
TokenStorageInterface $tokenStorage,
\H5PCore $core,
H5POptions $options,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $entityManager,
RouterInterface $router,
RequestStack $requestStack,
Packages $packages,
\H5PContentValidator $contentValidator
)
{
RouterInterface $router,
RequestStack $requestStack,
Packages $packages,
\H5PContentValidator $contentValidator
) {
parent::__construct($tokenStorage);
$this->core = $core;
$this->options = $options;
Expand Down Expand Up @@ -218,7 +215,9 @@ public function getFilteredParameters(Content $content): ?object
'filtered' => $content->getFilteredParameters(),
'embedType' => 'div',
];
if (!empty($contentData['filtered'] && $contentData['filtered'] == '{}')) $contentData['filtered'] = null;
if (!empty($contentData['filtered'] && $contentData['filtered'] == '{}')) {
$contentData['filtered'] = null;
}

return $this->core->filterParameters($contentData);
}
Expand Down Expand Up @@ -349,5 +348,4 @@ public function getOptions(): H5POptions
{
return $this->options;
}

}
6 changes: 2 additions & 4 deletions Core/H5POptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Studit\H5PBundle\Core;


use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -135,7 +134,7 @@ public function getAbsoluteH5PPathWithSlash(): string
$dir = $this->getOption('storage_dir');
$dir = $dir[0] === '/' ? $dir : '/' . $dir;

return $this->getAbsoluteWebPath() . $dir .'/';
return $this->getAbsoluteWebPath() . $dir . '/';
}
public function getAbsoluteH5PPath(): string
{
Expand All @@ -147,7 +146,7 @@ public function getAbsoluteH5PPath(): string

public function getAbsoluteWebPath(): string
{
return $this->projectRootDir .'/'. $this->getOption('web_dir');
return $this->projectRootDir . '/' . $this->getOption('web_dir');
}

public function getLibraryFileUrl($libraryFolderName, $fileName): string
Expand All @@ -159,5 +158,4 @@ public function getH5PAssetPath(): string
{
return '/bundles/studith5p/h5p';
}

}
58 changes: 34 additions & 24 deletions Core/H5PSymfony.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php


namespace Studit\H5PBundle\Core;


use DateTimeInterface;
use Doctrine\DBAL\Exception;
use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Exception\GuzzleException;
use JsonSerializable;
use Studit\H5PBundle\DependencyInjection\Configuration;
use Studit\H5PBundle\Editor\EditorStorage;
use Studit\H5PBundle\Entity\Content;
Expand All @@ -23,8 +22,6 @@
use Studit\H5PBundle\Event\H5PEvents;
use Studit\H5PBundle\Event\LibrarySemanticsEvent;
use GuzzleHttp\Client;
use Symfony\Component\Intl\Languages;
use Symfony\Component\Intl\Timezones;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -87,16 +84,16 @@ class H5PSymfony implements \H5PFrameworkInterface
* @param RouterInterface $router
*/
public function __construct(
H5POptions $options,
EditorStorage $editorStorage,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $manager,
?Session $session,
?RequestStack $requestStack,
H5POptions $options,
EditorStorage $editorStorage,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $manager,
?Session $session,
?RequestStack $requestStack,
AuthorizationCheckerInterface $authorizationChecker,
EventDispatcherInterface $eventDispatcher,
RouterInterface $router)
{
EventDispatcherInterface $eventDispatcher,
RouterInterface $router
) {
$this->options = $options;
$this->editorStorage = $editorStorage;
$this->tokenStorage = $tokenStorage;
Expand Down Expand Up @@ -158,8 +155,7 @@ public function fetchExternalData(
$headers = [],
$files = [],
$method = 'POST'
)
{
) {
$options = [];
if (!empty($data)) {
$options['headers'] = ['Content-Type' => 'application/x-www-form-urlencoded'];
Expand Down Expand Up @@ -194,7 +190,7 @@ public function fetchExternalData(
// http://guzzle.readthedocs.io/en/latest/request-options.html#sink-option
return true;
}
if($fullData){
if ($fullData) {
// Compatibility with response of h5p.classe.php
return [
'status' => $response->getStatusCode(),
Expand Down Expand Up @@ -510,7 +506,7 @@ public function saveLibraryData(&$libraryData, $new = true)
$this->manager->flush();
$libraryData['libraryId'] = $library->getId();
if ($libraryData['runnable']) {
$h5p_first_runnable_saved = $this->getOption('first_runnable_saved', FALSE);
$h5p_first_runnable_saved = $this->getOption('first_runnable_saved', false);
if (!$h5p_first_runnable_saved) {
$this->setOption('first_runnable_saved', 1);
}
Expand All @@ -527,7 +523,7 @@ public function saveLibraryData(&$libraryData, $new = true)
$library->setSemantics($libraryData['semantics']);
$library->setHasIcon($libraryData['hasIcon']);
$library->setMetadataSettings($libraryData['metadataSettings']);
$library->setAddTo(isset($libraryData['addTo']) ? json_encode($libraryData['addTo']) : NULL);
$library->setAddTo(isset($libraryData['addTo']) ? json_encode($libraryData['addTo']) : null);
$this->manager->persist($library);
$this->manager->flush();
$this->deleteLibraryDependencies($libraryData['libraryId']);
Expand Down Expand Up @@ -574,7 +570,7 @@ private function pathsToCsv($libraryData, $key)
/**
* @inheritDoc
*/
public function insertContent($contentData, $contentMainId = NULL)
public function insertContent($contentData, $contentMainId = null)
{
$content = new Content();
return $this->storeContent($contentData, $content);
Expand Down Expand Up @@ -683,7 +679,6 @@ public function deleteLibraryUsage($contentId): void
$this->manager->remove($contentLibrary);
}
$this->manager->flush();

}

/**
Expand Down Expand Up @@ -894,7 +889,7 @@ public function getOption($name, $default = null)
try {
// return default if db/table still not created
return $this->options->getOption($name, $default);
} catch (ConnectionException|TableNotFoundException $e) {
} catch (ConnectionException | TableNotFoundException $e) {
return $default;
}
}
Expand Down Expand Up @@ -966,7 +961,7 @@ public function getNumContent($libraryId, $skip = null)
/**
* @inheritDoc
*/
public function isContentSlugAvailable($slug)
public function isContentSlugAvailable($slug): bool
{
throw new \Exception();
}
Expand Down Expand Up @@ -1122,10 +1117,11 @@ public function replaceContentTypeCache($contentTypeCache): void
}

/**
* @param $tableClassName
* @param string $tableClassName
* @throws Exception
* @return void
*/
private function truncateTable($tableClassName)
private function truncateTable(string $tableClassName): void
{
$cmd = $this->manager->getClassMetadata($tableClassName);
$connection = $this->manager->getConnection();
Expand All @@ -1144,11 +1140,20 @@ public function libraryHasUpgrade($library): bool
return false;
}

/**
* @param JsonSerializable $metadata
* @param string $lang
* @return mixed
*/
public function replaceContentHubMetadataCache($metadata, $lang)
{
// TODO: Implement replaceContentHubMetadataCache() method.
}

/**
* @param string $lang
* @return JsonSerializable
*/
public function getContentHubMetadataCache($lang = 'en')
{
// TODO: Implement getContentHubMetadataCache() method.
Expand All @@ -1162,6 +1167,11 @@ public function getContentHubMetadataChecked($lang = 'en'): ?string
return $date->format(DateTimeInterface::RFC7231);
}

/**
* @param $time
* @param $lang
* @return bool
*/
public function setContentHubMetadataChecked($time, $lang = 'en')
{
// TODO: Implement setContentHubMetadataChecked() method.
Expand Down
Loading

0 comments on commit 1023e79

Please sign in to comment.