+ /**
+ * Check that important directories are writable.
+ *
+ * @return array
+ * Any CRM_Utils_Check_Message instances that need to be generated.
+ */
+ public function checkDirsWritable() {
+ $notWritable = array();
+
+ $config = CRM_Core_Config::singleton();
+ $directories = array(
+ 'uploadDir' => ts('Temporary Files Directory'),
+ 'imageUploadDir' => ts('Images Directory'),
+ 'customFileUploadDir' => ts('Custom Files Directory'),
+ 'extensionsDir' => ts('CiviCRM Extensions Directory'),
+ );
+
+ foreach ($directories as $directory => $label) {
+ $file = CRM_Utils_File::createFakeFile($config->$directory);
+
+ if ($file === FALSE) {
+ $notWritable[] = "$label ({$config->$directory})";
+ }
+ else {
+ $dirWithSlash = CRM_Utils_File::addTrailingSlash($config->$directory);
+ unlink($dirWithSlash . $file);
+ }
+ }
+
+ $messages = array();
+
+ if (!empty($notWritable)) {
+ $messages[] = new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ ts('The %1 is not writable. Please check your file permissions.', array(
+ 1 => implode(', ', $notWritable),
+ 'count' => count($notWritable),
+ 'plural' => 'The following directories are not writable: %1. Please check your file permissions.',
+ )),
+ ts('Directory not writable', array(
+ 'count' => count($notWritable),
+ 'plural' => 'Directories not writable',
+ )),
+ \Psr\Log\LogLevel::ERROR,
+ 'fa-ban'
+ );
+ }
+
+ return $messages;
+ }