Commit e977bed8 authored by tguillon's avatar tguillon
Browse files

Correction de l'enregistrement lors de la création d'une nouvelle

entité avec un logo.
parent 84474bd4
......@@ -81,12 +81,12 @@ class OrganisationsController extends AppController {
$this->redirect($this->Referers->get());
}
$success = false;
$success = true;
$this->Organisation->begin();
$recup = $this->Organisation->saveAddEditForm($this->request->data);
$success = false !== $this->Organisation->saveAddEditForm($this->request->data) && $success;
if (is_array($recup)) {
if ($success === true) {
$idOrganisation = $this->Organisation->getInsertID();
$success = $this->_insertRoles($idOrganisation);
......@@ -760,7 +760,7 @@ class OrganisationsController extends AppController {
}
}
}
if ($success == true) {
$this->Role->commit();
return(true);
......
......@@ -160,35 +160,32 @@ class Organisation extends AppModel {
* @version V0.9.0
*/
public function saveAddEditForm($data) {
if (isset($data[$this->alias]['logo_file']['tmp_name'])) {
$logo = $data[$this->alias]['logo_file'];
}
unset($data[$this->alias]['logo_file']);
$this->create($data);
$success = $this->save();
if ($success) {
if (isset($data[$this->alias]['logo_file']['tmp_name'])) {
$file = $data[$this->alias]['logo_file'];
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
if (!empty($file['tmp_name'])) {
if (isset($logo['tmp_name'])) {
$extension = strtolower(pathinfo($logo['name'], PATHINFO_EXTENSION));
if (!empty($logo['tmp_name'])) {
$oldextension = $this->field('logo');
$oldfile = IMAGES . 'logos' . DS . $this->id . '.' . $oldextension;
if (file_exists($oldfile)) {
$success = $success && unlink($oldfile);
}
$success = $success && move_uploaded_file($file['tmp_name'], IMAGES . 'logos' . DS . $this->id . '.' . $extension);
$success = $success && move_uploaded_file($logo['tmp_name'], IMAGES . 'logos' . DS . $this->id . '.' . $extension);
if ($success) {
$success = $success && $this->saveField('logo', $extension);
}
}
}
if (isset($data[$this->alias]['model_file'])) {
$file = $data[$this->alias]['model_file'];
if (!empty($file['tmp_name'])) {
$oldfile = 'files' . DS . 'modeles' . DS . $this->id . '.odt';
if (file_exists($oldfile)) {
$success = $success && unlink($oldfile);
}
$success = $success && move_uploaded_file($file['tmp_name'], 'files' . DS . 'modeles' . DS . $this->id . '.odt');
}
}
}
return $success;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment