-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add image uploads #76
Open
angeluss88
wants to merge
21
commits into
master
Choose a base branch
from
add-image-uploads
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
df90aa0
add-media. CRUD and filestack uploader
d3b3925
add back link and styles
c5276ff
remove desc column
ab7a33d
change index styles
a549fcd
CS changes
8a2f928
fixes
cacf24d
add guzzle client
a0b7304
use filesystem component for upload file
140b42d
add fs_api parameter
7b6fb6b
add behat feature for media
a499660
add filestack section to readme
1d5d286
add params to circle
9e36ac6
changes to media feature
826e648
fix media feature eventhost for circle
212596e
add param to behat.yml.dist
13b55ff
add ci params
f0e0ac9
revert redundant changes
5a6b01d
fix media feature
5cd69f6
add check folder permissions
f0a9bd0
change ci config add folder permissions
c6dbfed
add translation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ app/config/parameters.yml | |
|
||
composer.phar | ||
behat.yml | ||
.idea | ||
!web/uploads/.gitkeep | ||
!web/uploads/media/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,8 @@ parameters: | |
# default email for bot from which email is sent | ||
from_email: [email protected] | ||
|
||
admin_password: admin | ||
admin_password: admin | ||
#filestack params | ||
media.uploadPath: %kernel.root_dir%/../web/uploads/media/ | ||
media.uploadUrl: /uploads/media/ | ||
filestack.api_key: A3w1aZwZmQBibC09rAcZnz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,7 @@ parameters: | |
from_email: [email protected] | ||
|
||
admin_password: admin | ||
|
||
media.uploadPath: %kernel.root_dir%/../web/uploads/media/ | ||
media.uploadUrl: /uploads/media/ | ||
filestack.api_key: A3w1aZwZmQBibC09rAcZnz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
@backend | ||
Feature: Media settings | ||
In order to update media settings | ||
As an admin | ||
I should be able to edit media settings | ||
|
||
Background: | ||
Given following "Event": | ||
| ref | title | description | startDate | endDate | venue | email | host | | ||
| event | My event | My another awesome event! | 2016-03-01 10:00 | 2016-03-01 18:00 | Burj Khalifa Tower | [email protected] | http://localhost:8000 | | ||
| event2 | My other event | My other awesome event! | 2016-03-01 10:00 | 2016-03-01 18:00 | Burj Khalifa Tower | [email protected] | http://eventator.loc:8080 | | ||
| event3 | His event | His another awesome event! | 2016-04-01 10:00 | 2016-04-01 18:00 | Kuala-lumpur Tower | [email protected] | http://event.com | | ||
And following "EventTranslation": | ||
| event | locale | | ||
| event | ru_RU | | ||
| event | de_DE | | ||
| event2 | ru_RU | | ||
| event2 | de_DE | | ||
| event3 | ru_RU | | ||
And following "Organizer": | ||
| ref | title | description | isActive | events | | ||
| organizer | My organizer | My another awesome organizer! | 1 | event,event2,event3 | | ||
| organizer2 | His organizer | His another awesome organizer! | 1 | event2,event3 | | ||
And following "OrganizerTranslation": | ||
| organizer | locale | | ||
| organizer | ru_RU | | ||
| organizer2 | de_DE | | ||
And following "Speech": | ||
| ref | title | description | language | event | | ||
| speech | symfony propagation | world symfony expansion | ru | event | | ||
| speech2 | php servers piece | php most popular language | en | event | | ||
| speech3 | doctrine must have | what you docrtine project should have | en | event | | ||
| speech4 | symfony propagation2 | world symfony expansion2 | en | event2 | | ||
| speech5 | php servers piece2 | php most popular language2 | en | event2 | | ||
| speech6 | doctrine must have2 | what you docrtine project should have2 | en | event2 | | ||
| speech7 | symfony propagation2 | world symfony expansion2 | en | event3 | | ||
| speech8 | php servers piece2 | php most popular language2 | en | event3 | | ||
| speech9 | doctrine must have2 | what you docrtine project should have2 | en | event3 | | ||
|
||
And following "SpeechTranslation": | ||
| speech | locale | | ||
| speech | ru_RU | | ||
| speech2 | de_DE | | ||
| speech3 | de_DE | | ||
| speech4 | ru_RU | | ||
| speech5 | de_DE | | ||
| speech6 | de_DE | | ||
| speech7 | ru_RU | | ||
| speech8 | de_DE | | ||
| speech9 | de_DE | | ||
And following "Program": | ||
| ref | title | isTopic | isActive | startDate | endDate | events | speech | | ||
| program | keynote | 1 | 1 | 2016-03-01 10:00 | 2016-03-01 10:30 | event | | | ||
| program2 | alex_symfony | 0 | 1 | 2016-03-01 10:30 | 2016-03-01 11:30 | event | speech | | ||
| program3 | phil_php | 0 | 1 | 2016-03-01 11:30 | 2016-03-01 12:30 | event | speech2 | | ||
| program4 | coffee1 | 1 | 1 | 2016-03-01 12:30 | 2016-03-01 13:00 | event | | | ||
| program5 | phil_doctrine | 0 | 1 | 2016-03-01 13:00 | 2016-03-01 14:30 | event | speech3 | | ||
| program6 | end_keynote | 1 | 1 | 2016-03-01 14:30 | 2016-03-01 15:00 | event | | | ||
| program7 | after_party | 1 | 1 | 2016-03-01 15:00 | 2016-03-01 18:00 | event | | | ||
| program8 | keynote | 1 | 1 | 2016-04-01 10:00 | 2016-04-01 10:30 | event2 | | | ||
| program9 | alex_symfony | 0 | 1 | 2016-04-01 10:30 | 2016-04-01 11:30 | event2 | speech4 | | ||
| program10 | phil_php | 0 | 1 | 2016-04-01 11:30 | 2016-04-01 12:30 | event2 | speech5 | | ||
| program11 | coffee1 | 1 | 1 | 2016-04-01 12:30 | 2016-04-01 13:00 | event2 | | | ||
| program12 | phil_doctrine | 0 | 1 | 2016-04-01 13:00 | 2016-04-01 14:30 | event2 | speech6 | | ||
| program13 | end_keynote | 1 | 1 | 2016-04-01 14:30 | 2016-04-01 15:00 | event2 | | | ||
| program14 | after_party | 1 | 1 | 2016-04-01 15:00 | 2016-04-01 18:00 | event2 | | | ||
| program15 | keynote | 1 | 1 | 2016-04-01 10:00 | 2016-04-01 10:30 | event3 | | | ||
| program16 | alex_symfony | 0 | 1 | 2016-04-01 10:30 | 2016-04-01 11:30 | event3 | speech7 | | ||
| program17 | phil_php | 0 | 1 | 2016-04-01 11:30 | 2016-04-01 12:30 | event3 | speech8 | | ||
| program18 | coffee1 | 1 | 1 | 2016-04-01 12:30 | 2016-04-01 13:00 | event3 | | | ||
| program19 | phil_doctrine | 0 | 1 | 2016-04-01 13:00 | 2016-04-01 14:30 | event3 | speech9 | | ||
| program20 | end_keynote | 1 | 1 | 2016-04-01 14:30 | 2016-04-01 15:00 | event3 | | | ||
| program21 | after_party | 1 | 1 | 2016-04-01 15:00 | 2016-04-01 18:00 | event3 | | | ||
And following "ProgramTranslation": | ||
| program | locale | | ||
| program | ru_RU | | ||
| program2 | de_DE | | ||
| program3 | de_DE | | ||
| program4 | de_DE | | ||
| program5 | de_DE | | ||
| program6 | de_DE | | ||
| program7 | de_DE | | ||
| program8 | de_DE | | ||
| program9 | de_DE | | ||
| program10 | de_DE | | ||
| program11 | de_DE | | ||
| program12 | de_DE | | ||
| program13 | de_DE | | ||
| program14 | de_DE | | ||
| program15 | de_DE | | ||
| program16 | de_DE | | ||
| program17 | de_DE | | ||
| program18 | de_DE | | ||
| program19 | de_DE | | ||
| program20 | de_DE | | ||
| program21 | de_DE | | ||
And following "Speaker": | ||
| ref | firstName | lastName | Company | email | homepage | twitter | events | speeches | | ||
| speaker | Phill | Pilow | Reseach Supplier | | | | event,event2,event3 | speech2,speech3,speech5,speech6,speech8,speech9 | | ||
| speaker2 | Alex | Demchenko | KnpLabs | | http://451f.com.ua | https://twitter.com/twitter | event,event2,event3 | speech,speech4,speech7 | | ||
And following "SpeakerTranslation": | ||
| speaker | locale | | ||
| speaker | ru_RU | | ||
| speaker2 | de_DE | | ||
And following "Sponsor": | ||
| ref | company | description | homepage | type | isActive | events | | ||
| sponsor | Reseach Supplier | NASA research center | http://nasa.gov.us | 1 | 1 | event,event2,event3 | | ||
| sponsor2 | KnpLabs | Happy awesome developer | http://knplabs.com | 2 | 1 | event | | ||
And following "SponsorTranslation": | ||
| sponsor | locale | | ||
| sponsor | de_DE | | ||
| sponsor2 | de_DE | | ||
And following "Media": | ||
| title | filename | created_date | updated_date | | ||
| Media1 | logo.png | 2017-10-27 16:02 | 2017-10-27 16:02 | | ||
| Media2 | logo.png | 2017-10-27 17:02 | 2017-10-27 17:02 | | ||
|
||
@javascript | ||
Scenario: Admin should have access to the media manage | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "1;Media1" | ||
And I should see the row containing "2;Media2" | ||
When I click "Edit" on the row containing "1;Media1" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
|
||
@javascript | ||
Scenario: Admin should be able to add media | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I click "Add Media" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
And I fill in "Title" with "Media3" | ||
And I press "Upload file" | ||
Then I wait "10" seconds | ||
Then I should see " My Device " | ||
And I attach the file "test.png" to "fsp-fileUpload" | ||
Then I should see "Edit Image" | ||
Then I wait "15" seconds | ||
And I click on the element with css selector ".fsp-button--primary" | ||
Then I wait "10" seconds | ||
And I press "Add" | ||
Then I wait for a form | ||
Then I should see "Media Media3 added." | ||
Then I should see the row containing "3;Media3" | ||
|
||
@javascript | ||
Scenario: Admin should be able to update media settings | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "2;Media2" | ||
When I click "Edit" on the row containing "2;Media2" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
And I fill in "Title" with "Media2_1" | ||
And I fill in "Media Description" with "Awesome media" | ||
And I fill in "Copyright Info" with "Test media" | ||
And I press "Update" | ||
Then I wait for a form | ||
Then I should see "Media Media2_1 updated." | ||
Then I should see the row containing "2;Media2_1" | ||
|
||
@javascript | ||
Scenario: Admin should be delete to the media | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "1;Media1" | ||
Then I delete the record with id "1" | ||
Then I wait for a form | ||
Then I should see "Media deleted." | ||
Then I should not see the row containing "1;Media1" |
121 changes: 121 additions & 0 deletions
121
src/Event/EventBundle/Controller/Backend/MediaController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace Event\EventBundle\Controller\Backend; | ||
|
||
use Guzzle\Http\Client; | ||
use Symfony\Component\Config\Definition\Exception\Exception; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Filesystem\Exception\IOExceptionInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Event\EventBundle\Controller\Controller; | ||
use Event\EventBundle\Entity\Media; | ||
use Event\EventBundle\Form\Type\MediaType; | ||
|
||
class MediaController extends Controller | ||
{ | ||
|
||
public function getUploadPath() | ||
{ | ||
return $this->container->getParameter('media.uploadPath'); | ||
} | ||
|
||
public function getUploadUrl(){ | ||
return $this->container->getParameter('media.uploadUrl'); | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
return $this->render('EventEventBundle:Backend/Media:index.html.twig', array( | ||
'media' => $this->getRepository('EventEventBundle:Media')->findAll(), | ||
'uploadPath' => $this->getUploadPath(), | ||
'uploadUrl' => $this->getUploadUrl() | ||
)); | ||
} | ||
|
||
public function manageAction(Request $request, $id = null) | ||
{ | ||
$oldFileName = ''; | ||
if ($id === null) { | ||
$media = new Media(); | ||
} else { | ||
$media = $this->findOr404('EventEventBundle:Media', $id); | ||
$oldFileName = $media->getFilename(); | ||
} | ||
|
||
$form = $this->createForm(MediaType::class, $media); | ||
|
||
if ($request->getMethod() === 'POST') { | ||
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
$media->setUpdated(new \DateTime()); | ||
|
||
if ($oldFileName !== $media->getFilename()) { | ||
$url = $request->request->get('file_url'); | ||
$path = $this->getUploadPath(); | ||
$media->setFilename(time() . '_' . $media->getFilename()); | ||
$file = $this->getFile($url); | ||
|
||
$fs = new Filesystem(); | ||
|
||
try { | ||
$fs->dumpFile($path . $media->getFilename(), $file, 0777); | ||
} catch (IOExceptionInterface $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
} | ||
|
||
$this->getManager()->persist($media); | ||
$this->getManager()->flush(); | ||
|
||
$successFlashText = sprintf('Media %s updated.', $media->getTitle()); | ||
if (!$id) { | ||
$successFlashText = sprintf('Media %s added.', $media->getTitle()); | ||
} | ||
$this->setSuccessFlash($successFlashText); | ||
|
||
return $this->redirectToRoute('backend_media'); | ||
} | ||
} | ||
|
||
return $this->render('EventEventBundle:Backend/Media:manage.html.twig', [ | ||
'media' => $media, | ||
'form' => $form->createView(), | ||
'fs_api' => $this->container->getParameter('filestack.api_key'), | ||
]); | ||
} | ||
|
||
protected function checkAccessFolder($path){ | ||
if(is_dir($path)){ | ||
chmod($path, 0777); | ||
} else { | ||
mkdir($path, 0777, true); | ||
} | ||
} | ||
|
||
protected function getFile($url) | ||
{ | ||
$client = new Client(); | ||
$file = $client->createRequest('GET', $url)->send()->getBody(true); | ||
|
||
return $file; | ||
} | ||
|
||
public function deleteAction($id) | ||
{ | ||
$this->isGrantedAdmin(); | ||
$translator = $this->get('translator'); | ||
|
||
$entity = $this->findOr404('EventEventBundle:Media', $id); | ||
$file = $this->getUploadPath() . $entity->getFilename(); | ||
$this->getManager()->remove($entity); | ||
$this->getManager()->flush(); | ||
if (is_file($file)) { | ||
unlink($file); | ||
} | ||
|
||
$this->setSuccessFlash($translator->trans('Media deleted.')); | ||
|
||
return $this->redirectToRoute('backend_media'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CS fix