Skip to content

Commit

Permalink
add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ediathome committed Nov 22, 2018
1 parent f32f5be commit 706aecf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
13 changes: 13 additions & 0 deletions app/Resources/views/install/ioexception.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}

{% block title %}File System Error{% endblock %}

{% block body %}

<h1>Exception</h1>

<div class="alert {{ type }}">
{{ message|raw }}
</div>

{% endblock %}
16 changes: 13 additions & 3 deletions src/AppBundle/Controller/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ class InstallerController extends Controller
public function configure(Request $request)
{
$conf = new InstallerConfig();
# $conf->
$f = $this->createForm(InstallerConfigType::class, $conf);
$f->get('server_path')->setData($this->default_server_path());

$f = $this->createForm(InstallerConfigType::class, $conf, array(
'downloader' => $this->get('app.downloader')
));
try {
$f->get('server_path')->setData($this->default_server_path());
} catch (\Exception $e) {
return $this->render('install/ioexception.html.twig', array(
'message' => $e->getMessage().'<p>Please check your access rights for folder <code>'.$this->getParameter('app.default_shops_dir').'</code>',
'type' => 'alert-warning'
)
);
}

$f->handleRequest($request);

Expand Down
8 changes: 5 additions & 3 deletions src/AppBundle/Entity/InstallerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class InstallerConfig
{

protected $presta_version;
/**
* @Assert\GreaterThan(0)
Expand All @@ -17,9 +18,10 @@ class InstallerConfig
protected $presta_source_dir;
protected $shop_index;

public function __construct() {
$this->init_data();
}
public function __construct()
{
$this->init_data();
}
public function getPrestaVersion()
{
return $this->presta_version;
Expand Down
8 changes: 6 additions & 2 deletions src/AppBundle/Form/InstallerConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace AppBundle\Form;
use AppBundle\Entity\VersionDownload;
use AppBundle\Entity\InstallerConfig;
use AppBundle\Utils\Downloader;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -22,6 +23,8 @@ public static function loadValidatorMetadata(ClassMetadata $metadata)
$metadata->addPropertyConstraint('number_of_installations', new Assert\GreaterThan(0));
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$this->downloader = $options['downloader'];

$builder->add(
'presta_version',
ChoiceType::class,
Expand All @@ -43,13 +46,14 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults(array(
'data_class' => InstallerConfig::class,
));
$resolver->setRequired('downloader');
}
private function versions_choice()
{
$rv = [];
$av = VersionDownload::available_versions();
$av = $this->downloader->available_versions();
foreach ($av as $k => $v) {
$rv[$v['version']] = $v['version'];
$rv[$v->version()] = $v->version();
}
$rv = array_reverse($rv);
return $rv;
Expand Down

0 comments on commit 706aecf

Please sign in to comment.