Fix edit document using document repository (with flysystem)

pull/3016/head
Julio Montoya 5 years ago
parent 4572bcf79d
commit a67c7c6442
  1. 3
      .env
  2. 74
      config/packages/hwi_oauth.yaml
  3. 4
      config/packages/security.yaml
  4. 11
      main/document/edit_document.php
  5. 7
      src/CoreBundle/Controller/ResourceController.php
  6. 5
      src/CoreBundle/Entity/Resource/ResourceFile.php
  7. 13
      src/CourseBundle/Repository/CDocumentRepository.php

@ -1,11 +1,8 @@
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. # Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> doctrine/doctrine-bundle ### ###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_HOST="{{DATABASE_HOST}}" DATABASE_HOST="{{DATABASE_HOST}}"
DATABASE_PORT="{{DATABASE_PORT}}" DATABASE_PORT="{{DATABASE_PORT}}"
DATABASE_NAME="{{DATABASE_NAME}}" DATABASE_NAME="{{DATABASE_NAME}}"

@ -1,38 +1,38 @@
hwi_oauth: hwi_oauth:
connect: connect:
account_connector: chamilo_user.security.user_provider account_connector: chamilo_user.security.user_provider
firewall_names: firewall_names:
- admin - admin
resource_owners: resource_owners:
github: github:
type: github type: github
client_id: '%env(GITHUB_ID)%' client_id: '%env(GITHUB_ID)%'
client_secret: '%env(GITHUB_SECRET)%' client_secret: '%env(GITHUB_SECRET)%'
facebook: facebook:
type: facebook type: facebook
client_id: '%env(FB_ID)%' client_id: '%env(FB_ID)%'
client_secret: '%env(FB_SECRET)%' client_secret: '%env(FB_SECRET)%'
google: google:
type: google type: google
client_id: '%env(GOOGLE_ID)%' client_id: '%env(GOOGLE_ID)%'
client_secret: '%env(GOOGLE_SECRET)%' client_secret: '%env(GOOGLE_SECRET)%'
scope: "email profile" scope: "email profile"
my_custom_oauth2: my_custom_oauth2:
type: oauth2 type: oauth2
client_id: '<client_id>' client_id: '<client_id>'
client_secret: '<client_secret>' client_secret: '<client_secret>'
access_token_url: 'https://path.to/oauth/v2/token' access_token_url: 'https://path.to/oauth/v2/token'
authorization_url: 'https://path.to/oauth/v2/authorize' authorization_url: 'https://path.to/oauth/v2/authorize'
infos_url: 'https://path.to/api/user' infos_url: 'https://path.to/api/user'
scope: user_details scope: user_details
user_response_class: HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse user_response_class: HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse
paths: {identifier: id, nickname: username, realname: fullname} paths: {identifier: id, nickname: username, realname: fullname}
fosub: fosub:
# try 30 times to check if a username is available (foo, foo1, foo2 etc) # try 30 times to check if a username is available (foo, foo1, foo2 etc)
username_iterations: 30 username_iterations: 30
# mapping between resource owners (see below) and properties # mapping between resource owners (see below) and properties
properties: properties:
github: githubId github: githubId
google: googleId google: googleId
facebook: facebookId facebook: facebookId
my_custom_provider: customId my_custom_provider: customId

@ -81,8 +81,8 @@ security:
facebook: "/login/check-facebook" facebook: "/login/check-facebook"
google: "/login/check-google" google: "/login/check-google"
github: "/login/check-github" github: "/login/check-github"
login_path: /login_oauth login_path: /login
failure_path: /login_oauth failure_path: /login
use_forward: false use_forward: false
oauth_user_provider: oauth_user_provider:
service: chamilo_user.security.user_provider service: chamilo_user.security.user_provider

@ -281,10 +281,8 @@ if ($is_allowed_to_edit) {
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
$read_only_flag = empty($read_only_flag) ? 0 : 1; $read_only_flag = empty($read_only_flag) ? 0 : 1;
if ($read_only_flag == 0) { if ($read_only_flag == 0 && !empty($content)) {
if (!empty($content)) { $documentRepository->updateDocumentContent($document, $content);
$documentRepository->updateDocumentContent($document, $content);
}
} }
header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '')); header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''));
@ -303,10 +301,11 @@ $extension = $path_info['extension'] ?? '';
$em = Database::getManager(); $em = Database::getManager();
/** @var \Chamilo\CoreBundle\Entity\Resource\ResourceNode $node */ /** @var \Chamilo\CoreBundle\Entity\Resource\ResourceNode $node */
$node = $em->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($document_data['resource_node_id']); //$node = $em->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($document_data['resource_node_id']);
$node = $document->getResourceNode();
if (in_array($extension, ['html', 'htm'])) { if (in_array($extension, ['html', 'htm'])) {
$file = $node->getResourceFile(); $file = $document->getResourceNode()->getResourceFile();
if ($file) { if ($file) {
$content = $documentRepository->getDocumentContent($document_data['id']); $content = $documentRepository->getDocumentContent($document_data['id']);

@ -17,6 +17,7 @@ use Chamilo\CourseBundle\Controller\CourseControllerTrait;
use Chamilo\CourseBundle\Entity\CDocument; use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Repository\CDocumentRepository; use Chamilo\CourseBundle\Repository\CDocumentRepository;
use FOS\RestBundle\View\View; use FOS\RestBundle\View\View;
use League\Flysystem\MountManager;
use Liip\ImagineBundle\Service\FilterService; use Liip\ImagineBundle\Service\FilterService;
use Sonata\MediaBundle\Provider\ImageProvider; use Sonata\MediaBundle\Provider\ImageProvider;
use Sonata\MediaBundle\Provider\MediaProviderInterface; use Sonata\MediaBundle\Provider\MediaProviderInterface;
@ -415,7 +416,8 @@ class ResourceController extends BaseController implements CourseControllerInter
public function showAction( public function showAction(
Request $request, Request $request,
CDocumentRepository $documentRepo, CDocumentRepository $documentRepo,
FilterService $filterService FilterService $filterService,
MountManager $mountManager
): Response { ): Response {
$file = $request->get('file'); $file = $request->get('file');
$type = $request->get('type'); $type = $request->get('type');
@ -453,11 +455,10 @@ class ResourceController extends BaseController implements CourseControllerInter
//$media = $resourceFile->getMedia(); //$media = $resourceFile->getMedia();
//$format = MediaProviderInterface::FORMAT_REFERENCE; //$format = MediaProviderInterface::FORMAT_REFERENCE;
$fileName = $resourceNode->getName(); $fileName = $resourceNode->getName();
$filePath = $resourceFile->getFile()->getPathname(); $filePath = $resourceFile->getFile()->getPathname();
$mimeType = $resourceFile->getMimeType(); $mimeType = $resourceFile->getMimeType();
// @todo use $documentRepo
$fs = $this->get('oneup_flysystem.mount_manager')->getFilesystem('resources_fs'); $fs = $this->get('oneup_flysystem.mount_manager')->getFilesystem('resources_fs');
$stream = $fs->readStream($filePath); $stream = $fs->readStream($filePath);

@ -27,12 +27,11 @@ class ResourceFile
protected $id; protected $id;
/** /**
*
* @Assert\NotBlank() * @Assert\NotBlank()
* *
* @ORM\Column(type="string", length=255)
*
* @var string * @var string
*
* @ORM\Column(type="string", length=255)
*/ */
protected $name; protected $name;

@ -91,6 +91,11 @@ class CDocumentRepository extends ResourceRepository
} }
} }
/**
* @param int $id
*
* @return string
*/
public function getDocumentContent($id): string public function getDocumentContent($id): string
{ {
try { try {
@ -105,10 +110,15 @@ class CDocumentRepository extends ResourceRepository
} }
} }
/**
* @param CDocument $document
* @param string $content
*
* @return bool
*/
public function updateDocumentContent(CDocument $document, $content) public function updateDocumentContent(CDocument $document, $content)
{ {
try { try {
//$document = $this->find($id);
$resourceNode = $document->getResourceNode(); $resourceNode = $document->getResourceNode();
$resourceFile = $resourceNode->getResourceFile(); $resourceFile = $resourceNode->getResourceFile();
$fileName = $resourceFile->getFile()->getPathname(); $fileName = $resourceFile->getFile()->getPathname();
@ -120,7 +130,6 @@ class CDocumentRepository extends ResourceRepository
return true; return true;
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
throw new $exception;
} }
} }

Loading…
Cancel
Save