Skip to content

Commit

Permalink
fixed upload folder creation checks in 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed May 4, 2016
1 parent 04ebf50 commit c036329
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Installer {
return false;
«ENDIF»
}
$returnMessage = $this->__f('An error was encountered while creating the tables for the %s extension.', «IF targets('1.3.x')»array($this->getName())«ELSE»['«appName»'ENDIF»);
$returnMessage = $this->__f('An error was encountered while creating the tables for the %s extension.', «IF targets('1.3.x')»array($this->getName())«ELSE»['%s' => '«appName»'ENDIF»);
if (!System::isDevelopmentMode()) {
«IF targets('1.3.x'
$returnMessage .= ' ' . $this->__('Please enable the development mode by editing the /config/config.php file in order to reveal the error details.');
Expand Down Expand Up @@ -186,7 +186,7 @@ class Installer {
$entityManager->persist($registry);
$entityManager->flush();
} catch (\Exception $e) {
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('Error! Could not create a category registry for the %s entity.', ['«entity.name.formatForDisplay»']));
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('Error! Could not create a category registry for the %s entity.', ['%s' => '«entity.name.formatForDisplay»']));
$logger->error('{app}: User {user} could not create a category registry for {entities} during installation. Error details: {errorMessage}.', ['app' => '«appName»', 'user' => $userName, 'entities' => '«entity.nameMultiple.formatForDisplay»', 'errorMessage' => $e->getMessage()]);
}
$categoryRegistryIdsPerEntity['«entity.name.formatForCode»'] = $registry->getId();
Expand Down Expand Up @@ -299,7 +299,7 @@ class Installer {
«IF targets('1.3.x')»
return LogUtil::registerError($this->__f('An error was encountered while updating tables for the %s extension.', array($this->getName())));
«ELSE»
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while updating tables for the %s extension.', ['«appName»']));
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while updating tables for the %s extension.', ['%s' => '«appName»']));
$logger->error('{app}: User {user} could not update the database tables during the ugprade. Error details: {errorMessage}.', ['app' => '«appName»', 'user' => $userName, 'errorMessage' => $e->getMessage()]);
return false;
Expand Down Expand Up @@ -351,7 +351,7 @@ class Installer {
«IF targets('1.3.x'
return LogUtil::registerError($this->__f('An error was encountered while removing stored object workflows for the %s extension.', array($this->getName())));
«ELSE»
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while removing stored object workflows for the %s extension.', ['«appName»']));
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while removing stored object workflows for the %s extension.', ['%s' => '«appName»']));
$logger->error('{app}: User {user} could not remove stored object workflows during uninstallation.', ['app' => '«appName»', 'user' => $userName]);

return false;
Expand All @@ -378,7 +378,7 @@ class Installer {
«IF targets('1.3.x'
return LogUtil::registerError($this->__f('An error was encountered while dropping tables for the %s extension.', array($this->getName())));
«ELSE»
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while dropping tables for the %s extension.', ['«appName»']));
$this->addFlash(\Zikula_Session::MESSAGE_ERROR, $this->__f('An error was encountered while dropping tables for the %s extension.', ['%s' => '«appName»']));
$logger->error('{app}: User {user} could not remove the database tables during uninstallation. Error details: {errorMessage}.', ['app' => '«appName»', 'user' => $userName, 'errorMessage' => $e->getMessage()]);

return false;
Expand Down Expand Up @@ -428,7 +428,7 @@ class Installer {
«IF targets('1.3.x'
LogUtil::registerStatus($this->__f('The upload directories at [%s] can be removed manually.', $uploadPath));
«ELSE»
$this->addFlash(\Zikula_Session::MESSAGE_STATUS, $this->__f('The upload directories at [%s] can be removed manually.', $uploadPath));
$this->addFlash(\Zikula_Session::MESSAGE_STATUS, $this->__f('The upload directories at [%s] can be removed manually.', ['%s' => $uploadPath]));
«ENDIF»
«ENDIF»

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,35 +431,44 @@ class ControllerHelper {
}
«ELSE»
$fs = new Filesystem();
$flashBag = $this->session->getFlashBag();

try {
// Check if directory exist and try to create it if needed
if (!$fs->exists($uploadPath) && !$fs->mkdir($uploadPath, 0777)) {
$this->session->getFlashBag()->add(\Zikula_Session::MESSAGE_ERROR, $this->translator->__f('The upload directory "%s" does not exist and could not be created. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', [$uploadPath]));
// Check if directory exist and try to create it if needed
if (!$fs->exists($uploadPath)) {
try {
$fs->mkdir($uploadPath, 0777);
} catch (IOExceptionInterface $e) {
$flashBag->add(\Zikula_Session::MESSAGE_ERROR, $this->translator->__f('The upload directory "%s" does not exist and could not be created. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', ['%s' => $e->getPath()]));
$this->logger->error('{app}: The upload directory {directory} does not exist and could not be created.', ['app' => '«appName»', 'directory' => $uploadPath]);

return false;
}
}

// Check if directory is writable and change permissions if needed
if (!is_writable($uploadPath) && !$fs->chmod($uploadPath, 0777)) {
$this->session->getFlashBag()->add(\Zikula_Session::MESSAGE_WARNING, $this->translator->__f('Warning! The upload directory at "%s" exists but is not writable by the webserver.', [$uploadPath]));
// Check if directory is writable and change permissions if needed
if (!is_writable($uploadPath)) {
try {
$fs->chmod($uploadPath, 0777);
} catch (IOExceptionInterface $e) {
$flashBag->add(\Zikula_Session::MESSAGE_WARNING, $this->translator->__f('Warning! The upload directory at "%s" exists but is not writable by the webserver.', ['%s' => $e->getPath()]));
$this->logger->error('{app}: The upload directory {directory} exists but is not writable by the webserver.', ['app' => '«appName»', 'directory' => $uploadPath]);

return false;
}
}

// Write a htaccess file into the upload directory
$htaccessFilePath = $uploadPath . '/.htaccess';
$htaccessFileTemplate = '«rootFolder»/«IF !targets('1.3.x')»«if (systemModule) name.formatForCode else appName»/«ENDIF»«getAppDocPath»htaccessTemplate';
if (!$fs->exists($htaccessFilePath) && $fs->exists($htaccessFileTemplate)) {
// Write a htaccess file into the upload directory
$htaccessFilePath = $uploadPath . '/.htaccess';
$htaccessFileTemplate = '«rootFolder»/«if (systemModule) name.formatForCode else appName»/«getAppDocPath»htaccessTemplate';
if (!$fs->exists($htaccessFilePath) && $fs->exists($htaccessFileTemplate)) {
try {
$extensions = str_replace(',', '|', str_replace(' ', '', $allowedExtensions));
$htaccessContent = str_replace('__EXTENSIONS__', $extensions, file_get_contents($htaccessFileTemplate, false));
$fs->dumpFile($htaccessFilePath, $htaccessContent);
} catch (IOExceptionInterface $e) {
$flashBag->add(\Zikula_Session::MESSAGE_ERROR, $this->translator->__f('An error occured during creation of the .htaccess file in directory "%s".', ['%s' => $e->getPath()]));
$this->logger->error('{app}: An error occured during creation of the .htaccess file in directory {directory}.', ['app' => '«appName»', 'directory' => $uploadPath]);
}
} catch (IOExceptionInterface $e) {
$this->session->getFlashBag()->add(\Zikula_Session::MESSAGE_ERROR, $this->translator->__f('An error occured during creation of the .htaccess file in directory "%s".', [$e->getPath()]));
$this->logger->error('{app}: An error occured during creation of the .htaccess file in directory {directory}.', ['app' => '«appName»', 'directory' => $uploadPath]);
}
«ENDIF»

Expand Down

0 comments on commit c036329

Please sign in to comment.