/** * Save settings data. */ function black_lagoon_settings_submit($form, &$form_state) { $settings = array(); // Update image field foreach ($form_state['input']['images'] as $image) { if (is_array($image)) { $image = $image['image']; if ($image['image_delete']) { // Delete banner file file_unmanaged_delete($image['image_path']); // Delete banner thumbnail file file_unmanaged_delete($image['image_thumb']); } else { // Update image $settings[] = $image; } } } // Check for a new uploaded file, and use that if available. if ($file = file_save_upload('image_upload')) { $file->status = FILE_STATUS_PERMANENT; if ($image = _black_lagoon_save_image($file)) { // Put new image into settings $settings[] = $image; } } // Save settings black_lagoon_set_banners($settings); }
/** * Invokes system_retrieve_file() in several scenarios. */ function testFileRetrieving() { // Test 404 handling by trying to fetch a randomly named file. drupal_mkdir($sourcedir = 'public://' . $this->randomMachineName()); $filename = 'Файл для тестирования ' . $this->randomMachineName(); $url = file_create_url($sourcedir . '/' . $filename); $retrieved_file = system_retrieve_file($url); $this->assertFalse($retrieved_file, 'Non-existent file not fetched.'); // Actually create that file, download it via HTTP and test the returned path. file_put_contents($sourcedir . '/' . $filename, 'testing'); $retrieved_file = system_retrieve_file($url); // URLs could not contains characters outside the ASCII set so $filename // has to be encoded. $encoded_filename = rawurlencode($filename); $this->assertEqual($retrieved_file, 'public://' . $encoded_filename, 'Sane path for downloaded file returned (public:// scheme).'); $this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (public:// scheme).'); $this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (public:// scheme).'); file_unmanaged_delete($retrieved_file); // Test downloading file to a different location. drupal_mkdir($targetdir = 'temporary://' . $this->randomMachineName()); $retrieved_file = system_retrieve_file($url, $targetdir); $this->assertEqual($retrieved_file, "{$targetdir}/{$encoded_filename}", 'Sane path for downloaded file returned (temporary:// scheme).'); $this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (temporary:// scheme).'); $this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (temporary:// scheme).'); file_unmanaged_delete($retrieved_file); file_unmanaged_delete_recursive($sourcedir); file_unmanaged_delete_recursive($targetdir); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $messageHelper = $this->getHelperSet()->get('message'); $directory = $input->getArgument('directory'); if (!$directory) { $config = $this->getConfigFactory()->get('system.file'); $directory = $config->get('path.temporary') ?: file_directory_temp(); $directory .= '/' . CONFIG_STAGING_DIRECTORY; } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $config_export_file = $directory . '/config.tar.gz'; file_unmanaged_delete($config_export_file); try { $archiver = new ArchiveTar($config_export_file, 'gz'); $this->configManager = $this->getConfigManager(); // Get raw configuration data without overrides. foreach ($this->configManager->getConfigFactory()->listAll() as $name) { $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); } $this->targetStorage = $this->getConfigStorage(); // Get all override data from the remaining collections. foreach ($this->targetStorage->getAllCollectionNames() as $collection) { $collection_storage = $this->targetStorage->createCollection($collection); foreach ($collection_storage->listAll() as $name) { $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name))); } } } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } $messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file)); }
/** * Complete remote export. */ function complete() { // Download the export file. $this->download(); // Remove the export file from the server. file_unmanaged_delete($this->file_location); }
/** * {@inheritdoc} */ public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL) { $filename = isset($bundle) && $bundle->isProfile() ? $bundle->getProfileName() : 'generated_features'; // If no packages were specified, get all packages. if (empty($packages)) { $packages = $this->featuresManager->getPackages(); } elseif (count($packages) == 1) { // Single package export, so name tar archive by package name. $filename = current($packages)['machine_name']; } $return = []; $this->archiveName = $filename . '.tar.gz'; $archive_name = file_directory_temp() . '/' . $this->archiveName; if (file_exists($archive_name)) { file_unmanaged_delete($archive_name); } $archiver = new ArchiveTar($archive_name); // Add package files. foreach ($packages as $package) { if (count($packages) == 1) { // Single module export, so don't generate entire modules dir structure. $package['directory'] = $package['machine_name']; } $this->generatePackage($return, $package, $archiver); } return $return; }
/** * Try deleting a directory. */ function testDirectory() { // A directory to operate on. $directory = $this->createDirectory(); // Try to delete a directory $this->assertFalse(file_unmanaged_delete($directory), 'Could not delete the delete directory.'); $this->assertTrue(file_exists($directory), 'Directory has not been deleted.'); }
/** * Downloads a tarball of the site configuration. */ public function downloadExport() { file_unmanaged_delete(file_directory_temp() . '/config.tar.gz'); $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz'); // Get raw configuration data without overrides. foreach ($this->configManager->getConfigFactory()->listAll() as $name) { $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); } // Get all override data from the remaining collections. foreach ($this->targetStorage->getAllCollectionNames() as $collection) { $collection_storage = $this->targetStorage->createCollection($collection); foreach ($collection_storage->listAll() as $name) { $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name))); } } $request = new Request(array('file' => 'config.tar.gz')); return $this->fileDownloadController->download($request, 'temporary'); }
function parallax_bg_region5_validate($element, &$form_state) { global $base_url; $validateFile = array('file_validate_is_image' => array()); $UploadedFile = file_save_upload('parallax_bg_region5_image', $validateFile, "public://", FILE_EXISTS_REPLACE); if ($form_state['values']['delete_parallax_bg_region5_image'] == TRUE) { file_unmanaged_delete($form_state['values']['parallax_bg_region5_preview']); $form_state['values']['parallax_bg_region5_preview'] = NULL; } if ($UploadedFile) { $UploadedFile->status = FILE_STATUS_PERMANENT; file_save($UploadedFile); $file_url = file_create_url($UploadedFile->uri); $file_url = str_ireplace($base_url, '', $file_url); // set to form $form_state['values']['parallax_bg_region5_preview'] = $file_url; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configFile = $input->getOption('file'); $removeFiles = $input->getOption('remove-files'); $configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); if ($configFile) { $archiveTar = new ArchiveTar($configFile, 'gz'); $io->simple($this->trans('commands.config.import.messages.config_files_imported')); foreach ($archiveTar->listContent() as $file) { $io->info('[-] ' . $file['filename']); } try { $archiveTar->extract($configSyncDir . '/'); } catch (\Exception $e) { $io->error($e->getMessage()); return; } } $finder = new Finder(); $finder->in($configSyncDir); $finder->name("*.yml"); foreach ($finder as $configFile) { $configName = $configFile->getBasename('.yml'); $configFilePath = sprintf('%s/%s', $configSyncDir, $configFile->getBasename()); $config = $this->getConfigFactory()->getEditable($configName); $parser = new Parser(); $configData = $parser->parse(file_get_contents($configFilePath)); $config->setData($configData); if ($removeFiles) { file_unmanaged_delete($configFilePath); } try { $config->save(); } catch (\Exception $e) { $io->error($e->getMessage()); return; } } $io->success(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY)); }
/** * Cleanup files created during download(). * * It is expected that $files is returned from download(). Also, be aware that * each parent directory in the hierarchy may be removed if there are no more * files left in that directory. * * @param [] $files * Array of files as returned from download() method. */ public static function cleanup(array $files) { foreach ($files as $file_path => $file_name) { // Handle managed files. if (count(file_load_multiple([], ['uri' => $file_path])) > 0) { $file_obj = new \stdClass(); $file_obj->uri = $file_path; file_delete($file_obj); } else { file_unmanaged_delete($file_path); } // Remove all directories in the tree if the file was the last one in this // directory. $file_dir = dirname($file_path); while (count(file_scan_directory($file_dir, '/.*/')) === 0) { if (!is_dir($file_dir)) { break; } drupal_rmdir($file_dir); $file_dir = dirname($file_dir); } } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $directory = $input->getOption('directory'); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $configName = $input->getArgument('config-name'); $configExportFile = $directory . '/' . $configName . '.yml'; file_unmanaged_delete($configExportFile); $config = $this->getConfigFactory()->getEditable($configName); if ($config) { $yaml = Yaml::encode($config->getRawData()); // Save release file file_put_contents($configExportFile, $yaml); $output->writeln('[+] <info>' . sprintf($this->trans('commands.config.export.single.messages.export'), $configExportFile) . '</info>'); } else { $output->writeln('[+] <error>' . $this->trans('commands.config.export.single.messages.config-not-found') . '</error>'); } }
function site_bg_validate($element, &$form_state) { global $base_url; $validateFile = array('file_validate_is_image' => array()); $UploadedFile = file_save_upload('site_bg_image', $validateFile, "public://", FILE_EXISTS_REPLACE); if ($form_state['values']['delete_site_bg_image'] == TRUE) { // Delete layer file file_unmanaged_delete($form_state['values']['site_bg_preview']); $form_state['values']['site_bg_preview'] = NULL; } if ($UploadedFile) { // change file's status from temporary to permanent and update file database $UploadedFile->status = FILE_STATUS_PERMANENT; file_save($UploadedFile); $file_url = file_create_url($UploadedFile->uri); $file_url = str_ireplace($base_url, '', $file_url); // set to form $form_state['values']['site_bg_preview'] = $file_url; } }
public function testJavaScriptTranslation() { $user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages')); $this->drupalLogin($user); $config = \Drupal::config('locale.settings'); $langcode = 'xx'; // The English name for the language. This will be translated. $name = $this->randomMachineName(16); // Add custom language. $edit = array('predefined_langcode' => 'custom', 'langcode' => $langcode, 'label' => $name, 'direction' => LanguageInterface::DIRECTION_LTR); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); $this->container->get('language_manager')->reset(); // Build the JavaScript translation file. // Retrieve the source string of the first string available in the // {locales_source} table and translate it. $source = db_select('locales_source', 'l')->fields('l', array('source'))->condition('l.source', '%.js%', 'LIKE')->range(0, 1)->execute()->fetchField(); $search = array('string' => $source, 'langcode' => $langcode, 'translation' => 'all'); $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter')); $textarea = current($this->xpath('//textarea')); $lid = (string) $textarea[0]['name']; $edit = array($lid => $this->randomMachineName()); $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations')); // Trigger JavaScript translation parsing and building. _locale_rebuild_js($langcode); $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array(); $js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js'; $this->assertTrue($result = file_exists($js_file), String::format('JavaScript file created: %file', array('%file' => $result ? $js_file : 'not found'))); // Test JavaScript translation rebuilding. file_unmanaged_delete($js_file); $this->assertTrue($result = !file_exists($js_file), String::format('JavaScript file deleted: %file', array('%file' => $result ? $js_file : 'found'))); _locale_rebuild_js($langcode); $this->assertTrue($result = file_exists($js_file), String::format('JavaScript file rebuilt: %file', array('%file' => $result ? $js_file : 'not found'))); }
/** * Save settings data. */ function stability_settings_submit($form, &$form_state) { $settings = array(); if (isset($form_state['input']['sub_header_images'])) { foreach ($form_state['input']['sub_header_images'] as $image) { if (is_array($image)) { $image = $image['image']; if ($image['image_delete']) { $image['fid'] && ($file = file_load($image['fid'])) ? file_delete($file) : file_unmanaged_delete($image['image_path']); } else { $settings[] = $image; } } } } if ($file = file_save_upload('image_upload', array(), 'public://')) { $file->status = 1; file_save($file); $settings[] = array('fid' => $file->fid, 'image_path' => $file->uri); } variable_set(variable_get('theme_default', 'none') . '_sub_headers', $settings); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $messageHelper = $this->getMessageHelper(); $directory = $input->getArgument('directory'); if (!$directory) { $config = $this->getConfigFactory()->get('system.file'); $directory = $config->get('path.temporary') ?: file_directory_temp(); $directory .= '/' . CONFIG_STAGING_DIRECTORY; } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $config_name = $input->getArgument('config-name'); $config_export_file = $directory . '/' . $config_name . '.yml'; file_unmanaged_delete($config_export_file); $config = $this->getConfigFactory()->getEditable($config_name); if ($config) { $yaml = Yaml::encode($config->getRawData()); // Save release file file_put_contents($config_export_file, $yaml); $output->writeln('[+] <info>' . sprintf($this->trans('commands.config.export.single.messages.export'), $config_export_file) . '</info>'); } else { $output->writeln('[+] <error>' . $this->trans('commands.config.export.single.messages.config-not-found') . '</error>'); } }
$CSS .= $scss->compile($output); } // Preset Colours foreach ($presets as $k => $preset) { $maincolor = isset($preset->superhero_color_main) ? $preset->superhero_color_main : "false"; $textcolor = isset($preset->superhero_color_text) ? $preset->superhero_color_text : "false"; $linkcolor = isset($preset->superhero_color_link) ? $preset->superhero_color_link : "false"; $hovercolor = isset($preset->superhero_color_hover) ? $preset->superhero_color_hover : "false"; $headingcolor = isset($preset->superhero_color_heading) ? $preset->superhero_color_heading : "false"; $maincolor = empty($maincolor) ? "false" : $maincolor; $output = <<<SCSS \t\$maincolor: {$maincolor}; \t\$textcolor: {$textcolor}; \t\$linkcolor: {$linkcolor}; \t\$hovercolor: {$hovercolor}; \t\$headingcolor: {$headingcolor}; \t@import "global"; SCSS; try { $tmpCSS = $CSS . $scss->compile($output); } catch (exception $e) { drupal_set_message("fatal error: " . $e->getMessage(), 'error'); } $theme_path = drupal_get_path('theme', $theme->theme); $css_file = "public://" . $theme->theme . "-preset" . ($k + 1) . ".css"; //$css_file = $theme_path."/css/".$theme->theme."-preset".($k+1).".css"; file_unmanaged_save_data($tmpCSS, $css_file, FILE_EXISTS_REPLACE); //Remove all custom scss file_unmanaged_delete('public://' . $theme->theme . '-theme-preset' . ($k + 1) . '.css'); }
/** * {@inheritdoc} */ public function clear(FeedInterface $feed) { $feed_config = $feed->getConfigurationFor($this); $url = $feed_config['source']; \Drupal::cache()->delete('feeds_http_download:' . md5($url)); file_unmanaged_delete($this->prepareDirectory($url)); }
/** * Ensure a file entity can be saved when the file does not exist on disk. */ public function testFileRemovedFromDisk() { $this->drupalGet('file/test/1/0/1'); $test_file = $this->getTestFile('text'); $file_field_name = 'files[nested_file][]'; $edit = [$file_field_name => drupal_realpath($test_file->getFileUri())]; $this->drupalPostForm(NULL, $edit, t('Upload')); $this->drupalPostForm(NULL, array(), t('Save')); $fid = $this->getLastFileId(); /** @var $file \Drupal\file\FileInterface */ $file = $this->container->get('entity_type.manager')->getStorage('file')->load($fid); $file->setPermanent(); $file->save(); $this->assertTrue(file_unmanaged_delete($file->getFileUri())); $file->save(); $this->assertTrue($file->isPermanent()); $file->delete(); }
/** * Save settings data. */ function surreal_settings_submit(&$form, &$form_state) { $settings = array(); // Region parallax upload for ($i = 1; $i <= 6; $i++) { $fg = 'parallax_fg_region' . $i . '_image'; if ($file = file_load($form_state['values'][$fg])) { $file->status = FILE_STATUS_PERMANENT; file_save($file); file_usage_add($file, 'user', 'user', 1); variable_set($fg, $file->fid); } $bg = 'parallax_bg_region' . $i . '_image'; if ($file = file_load($form_state['values'][$bg])) { $file->status = FILE_STATUS_PERMANENT; file_save($file); file_usage_add($file, 'user', 'user', 1); variable_set($bg, $file->fid); } } // Update image field foreach ($form_state['input']['images'] as $image) { if (is_array($image)) { $image = $image['image']; if ($image['image_delete']) { // Delete banner file file_unmanaged_delete($image['image_path']); // Delete banner thumbnail file file_unmanaged_delete($image['image_thumb']); } else { // Update image $settings[] = $image; } } } // Check for a new uploaded file, and use that if available. if ($file = file_save_upload('image_upload')) { $file->status = FILE_STATUS_PERMANENT; if ($image = _surreal_save_image($file)) { // Put new image into settings $settings[] = $image; } } // Save settings surreal_set_banners($settings); }
/** * Save downloaded managed files. * * @param [] $downloaded_files * Array of downloaded files. */ protected function saveManaged(array $downloaded_files) { foreach ($downloaded_files as $file_path => $file_name) { $local_file_loaded = file_get_contents($file_path); $file = file_save_data($local_file_loaded, $file_path, FILE_EXISTS_REPLACE); if ($file) { if ($this->verbose) { $this->messageSet(t('Saved file %filename as managed file with fid %fid', ['%filename' => $file_name, '%fid' => $file->fid])); } } else { // Remove the file. file_unmanaged_delete($file_path); // Unset downloaded file if it was not saved as managed. unset($downloaded_files[$file_path]); if ($this->verbose) { $this->messageSet(t('Unable to save file %filename as managed file', ['%filename' => $file_name])); } } } return $downloaded_files; }
public function delete() { if ($this->checkFilePermissions($this->filename)) { file_unmanaged_delete(ConfigurationManagement::getStream() . '/' . $this->filename); } return $this; }
/** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); foreach ($entities as $entity) { // Delete all remaining references to this file. $file_usage = \Drupal::service('file.usage')->listUsage($entity); if (!empty($file_usage)) { foreach ($file_usage as $module => $usage) { \Drupal::service('file.usage')->delete($entity, $module); } } // Delete the actual file. Failures due to invalid files and files that // were already deleted are logged to watchdog but ignored, the // corresponding file entity will be deleted. file_unmanaged_delete($entity->getFileUri()); } }
/** * {@inheritdoc} */ public function flush($path = NULL) { // A specific image path has been provided. Flush only that derivative. if (isset($path)) { $derivative_uri = $this->buildUri($path); if (file_exists($derivative_uri)) { file_unmanaged_delete($derivative_uri); } return $this; } // Delete the style directory in each registered wrapper. $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::WRITE_VISIBLE); foreach ($wrappers as $wrapper => $wrapper_data) { if (file_exists($directory = $wrapper . '://styles/' . $this->id())) { file_unmanaged_delete_recursive($directory); } } // Let other modules update as necessary on flush. $module_handler = \Drupal::moduleHandler(); $module_handler->invokeAll('image_style_flush', array($this)); // Clear caches so that formatters may be added for this style. drupal_theme_rebuild(); Cache::invalidateTags($this->getCacheTagsToInvalidate()); return $this; }
/** * Resizes a list of imce items and returns succeeded ones. */ public function resizeItems(ImceFM $fm, array $items, $width, $height, $copy = FALSE) { $factory = \Drupal::service('image.factory'); $fs = \Drupal::service('file_system'); $success = array(); foreach ($items as $item) { $uri = $item->getUri(); $image = $factory->get($uri); // Check vallidity if (!$image->isValid()) { continue; } // Check if resizing is needed. $resize = $image->getWidth() != $width || $image->getHeight() != $height; if (!$resize && !$copy) { continue; } if ($resize && !$image->resize($width, $height)) { continue; } // Save $destination = $copy ? file_create_filename($fs->basename($uri), $fs->dirname($uri)) : $uri; if (!$image->save($destination)) { continue; } // Create a new file record. if ($copy) { $filename = $fs->basename($destination); $values = array('uid' => $fm->user->id(), 'status' => 1, 'filename' => $filename, 'uri' => $destination, 'filesize' => $image->getFileSize(), 'filemime' => $image->getMimeType()); $file = \Drupal::entityTypeManager()->getStorage('file')->create($values); // Check quota if ($errors = file_validate_size($file, 0, $fm->getConf('quota'))) { file_unmanaged_delete($destination); $fm->setMessage($errors[0]); } else { $file->save(); // Add imce item $item->parent->addFile($filename)->addToJs(); } } else { if ($file = Imce::getFileEntity($uri)) { $file->setSize($image->getFileSize()); $file->save(); } // Add to js $item->addToJs(); } $success[] = $item; } return $success; }
/** * {@inheritdoc} */ public function deleteAll() { $this->state->delete('drupal_css_cache_files'); $delete_stale = function ($uri) { // Default stale file threshold is 30 days. if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { file_unmanaged_delete($uri); } }; file_scan_directory('public://css', '/.*/', array('callback' => $delete_stale)); }
// Rebuild the theme registry. drupal_theme_rebuild(); if (flood_is_allowed('omega_' . $GLOBALS['theme'] . '_rebuild_registry_warning', 3)) { // Alert the user that the theme registry is being rebuilt on every // request. flood_register_event('omega_' . $GLOBALS['theme'] . '_rebuild_registry_warning'); drupal_set_message(t('The theme registry is being rebuilt on every request. Remember to <a href="!url">turn off</a> this feature on production websites.', array("!url" => url('admin/appearance/settings/' . $GLOBALS['theme']))), 'warning'); } } if (omega_theme_get_setting('omega_rebuild_aggregates', FALSE) && variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')) { foreach (array('css', 'js') as $type) { variable_del('drupal_' . $type . '_cache_files'); foreach (file_scan_directory('public://' . $type . '', '/.*/') as $file) { // Delete files that are older than 20 seconds. if (REQUEST_TIME - filemtime($file->uri) > 20) { file_unmanaged_delete($file->uri); } } } if (flood_is_allowed('omega_' . $GLOBALS['theme'] . '_rebuild_aggregates_warning', 3)) { // Alert the user that the theme registry is being rebuilt on every // request. flood_register_event('omega_' . $GLOBALS['theme'] . '_rebuild_aggregates_warning'); drupal_set_message(t('The CSS and JS aggregates are being rebuilt on every request. Remember to <a href="!url">turn off</a> this feature on production websites.', array("!url" => url('admin/appearance/settings/' . $GLOBALS['theme']))), 'warning'); } } } } /** * Implements hook_element_info_alter(). */
/** * Imports data for a provider that was manually uploaded in theme settings. * * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ private function importProviderData(FormStateInterface $form_state) { if ($form_state->getValue('clicked_button') === t('Save provider data')->render()) { $provider_path = ProviderManager::FILE_PATH; file_prepare_directory($provider_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $provider = $form_state->getValue('cdn_provider', $this->theme->getSetting('cdn_provider')); $file = "{$provider_path}/{$provider}.json"; if ($import_data = $form_state->getValue('cdn_provider_import_data', FALSE)) { file_unmanaged_save_data($import_data, $file, FILE_EXISTS_REPLACE); } elseif ($file && file_exists($file)) { file_unmanaged_delete($file); } // Clear the cached definitions so they can get rebuilt. $this->providerManager->clearCachedDefinitions(); } }
/** * Deletes a file by uri. */ public static function deleteFileUri($uri, $ignore_usage = FALSE) { // Managed file if ($file = Imce::getFileEntity($uri)) { if (!$ignore_usage && ($usage = \Drupal::service('file.usage')->listUsage($file))) { unset($usage['imce']); if ($usage) { drupal_set_message(t('%filename is in use by another application.', array('%filename' => $file->getFilename())), 'error'); return FALSE; } } $file->delete(); return TRUE; } // Unmanaged file return file_unmanaged_delete($uri); }
<?php /** * @file * Adminimal Menu Update file 7100. */ // Define Adminimal Menu path. $module_path = drupal_get_path('module', 'adminimal_admin_menu'); // Delete the "adminimal_admin_menu.js" file. file_unmanaged_delete($module_path . '/adminimal_admin_menu.js'); // Empty the "slicknav" folder. file_unmanaged_delete_recursive($module_path . '/slicknav'); // Delete the "slicknav" folder. drupal_rmdir($module_path . '/slicknav');
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $configName = $input->getArgument('config-name'); $configNames = [$configName]; if ($input->getOption('include-dependencies')) { $configNames += $this->getConfigDependencies($configName); } foreach ($configNames as $configName) { $config = $this->getConfigFactory()->getEditable($configName); $configExportFile = $directory . '/' . $configName . '.yml'; file_unmanaged_delete($configExportFile); if ($config) { $yaml = Yaml::encode($config->getRawData()); // Save configuration file. file_put_contents($configExportFile, $yaml); $io->info(sprintf($this->trans('commands.config.export.single.messages.export'), $configExportFile)); } else { $io->error($this->trans('commands.config.export.single.messages.config-not-found')); } } }