本文整理汇总了PHP中file_unmanaged_delete_recursive函数的典型用法代码示例。如果您正苦于以下问题:PHP file_unmanaged_delete_recursive函数的具体用法?PHP file_unmanaged_delete_recursive怎么用?PHP file_unmanaged_delete_recursive使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_unmanaged_delete_recursive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFileRetrieving
/**
* 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);
}
示例2: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$id = $this->entity->id;
$file_name = file_default_scheme() . "://js_injector/{$id}.js";
file_unmanaged_delete_recursive($file_name);
$this->entity->delete();
drupal_set_message($this->t('Js Injector deleted @label.', ['@label' => $this->entity->label()]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
示例3: save
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state)
{
$js_injector = $this->entity;
$status = $js_injector->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Js Injector.', ['%label' => $js_injector->label()]));
break;
default:
drupal_set_message($this->t('Saved the %label Js Injector.', ['%label' => $js_injector->label()]));
$file_name = file_default_scheme() . '://js_injector/' . $js_injector->id . '.js';
file_unmanaged_delete_recursive($file_name);
}
drupal_flush_all_caches();
$form_state->setRedirectUrl($js_injector->urlInfo('collection'));
}
示例4: testExportWrite
public function testExportWrite()
{
$package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
// Find out where package will be exported
list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle());
$path = $path . '/' . $full_name;
if (file_exists($path)) {
file_unmanaged_delete_recursive($path);
}
$this->assertFalse(file_exists($path), 'Package directory already exists.');
$this->generator->generatePackages('write', [self::PACKAGE_NAME], $this->assigner->getBundle());
$this->assertTrue(file_exists($path), 'Package directory was not generated.');
$this->assertTrue(file_exists($path . '/' . self::PACKAGE_NAME . '.info.yml'), 'Package info.yml not generated.');
$this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.');
$this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.');
}
示例5: testSubDirectory
/**
* Try deleting subdirectories with some files.
*/
function testSubDirectory()
{
// A directory to operate on.
$directory = $this->createDirectory();
$subdirectory = $this->createDirectory($directory . '/sub');
$filepathA = $directory . '/A';
$filepathB = $subdirectory . '/B';
file_put_contents($filepathA, '');
file_put_contents($filepathB, '');
// Delete the directory.
$this->assertTrue(file_unmanaged_delete_recursive($directory), 'Function reported success.');
$this->assertFalse(file_exists($filepathA), 'Test file A has been deleted.');
$this->assertFalse(file_exists($filepathB), 'Test file B has been deleted.');
$this->assertFalse(file_exists($subdirectory), 'Subdirectory has been deleted.');
$this->assertFalse(file_exists($directory), 'Directory has been deleted.');
}
示例6: preparePackage
/**
* Reads and merges in existing files for a given package or profile.
*
* @param array &$package
* The package.
* @param array $existing_packages
* An array of existing packages.
* @param \Drupal\features\FeaturesBundleInterface $bundle
* The bundle the package belongs to.
*/
protected function preparePackage(array &$package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) {
// If this package is already present, prepare files.
if (isset($existing_packages[$package['machine_name']])) {
$existing_directory = $existing_packages[$package['machine_name']];
$package['directory'] = $existing_directory;
// Merge in the info file.
$info_file_uri = $existing_directory . '/' . $package['machine_name'] . '.info.yml';
if (file_exists($info_file_uri)) {
$package['files']['info']['string'] = $this->mergeInfoFile($package['files']['info']['string'], $info_file_uri);
}
// Remove the config directory, as it will be replaced.
$config_directory = $existing_directory . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
if (is_dir($config_directory)) {
file_unmanaged_delete_recursive($config_directory);
}
}
}
示例7: preparePackage
/**
* Reads and merges in existing files for a given package or profile.
*
* @param array &$package
* The package.
* @param array $existing_packages
* An array of existing packages.
* @param \Drupal\features\FeaturesBundleInterface $bundle
* The bundle the package belongs to.
*/
protected function preparePackage(array &$package, array $existing_packages, FeaturesBundleInterface $bundle = NULL)
{
// If this package is already present, prepare files.
if (isset($existing_packages[$package['machine_name']])) {
$existing_directory = $existing_packages[$package['machine_name']];
$package['directory'] = $existing_directory;
// Merge in the info file.
$info_file_uri = $existing_directory . '/' . $package['machine_name'] . '.info.yml';
if (file_exists($info_file_uri)) {
$package['files']['info']['string'] = $this->mergeInfoFile($package['files']['info']['string'], $info_file_uri);
}
// Remove the config directories, as they will be replaced.
foreach (array_keys($this->featuresManager->getExtensionStorages()->getExtensionStorages()) as $directory) {
$config_directory = $existing_directory . '/' . $directory;
if (is_dir($config_directory)) {
file_unmanaged_delete_recursive($config_directory);
}
}
}
}
示例8: drupal_get_path
<?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');
示例9: init
/**
* Fully initializes the git clone entity after it has been created or loaded.
*
* @param bool $force
* Toggle determining whether or not to force a reinitialization.
*
* @return GitClone
* The current GitClone entity instance.
*
* @see GitClone::save()
* @see EntityController::load()
*
* @chainable
*/
public function init($force = FALSE)
{
if (!$force && isset($this->initialized)) {
return $this;
}
$this->initialized = TRUE;
// Ensure a Gitonomy repository is instantiated.
if (!$force && !isset($this->repository)) {
$options = _git_clone_gitonomy_options();
if (($path = $this->getPath(FALSE)) && !empty($this->url)) {
$git_exists = file_exists("{$path}/.git");
if (!$git_exists && in_array($this->refType, self::$allowedRefs)) {
try {
$this->repository = Admin::init($path, FALSE, $options);
$this->run('remote', array('add', 'origin', $this->url));
} catch (\Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
} elseif ($git_exists && in_array($this->refType, self::$allowedRefs)) {
$this->repository = new Repository($path, $options);
}
} else {
$temp_dir = 'temporary://git_clone-' . drupal_hash_base64(REQUEST_TIME);
if (file_prepare_directory($temp_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
$temp_dir = drupal_realpath($temp_dir);
drupal_register_shutdown_function(function () use($temp_dir) {
if (file_exists($temp_dir)) {
file_unmanaged_delete_recursive($temp_dir);
}
});
try {
$this->repository = Admin::init($temp_dir, FALSE, $options);
} catch (\Exception $e) {
watchdog('git_clone', $e->getMessage(), WATCHDOG_ERROR);
}
}
if (!$this->repository) {
drupal_set_message(t('Unable to create temporary git clone repository: @directory. Please verify your system temporary directory is writable.', array('@directory' => $temp_dir)), 'error');
}
}
}
// Initialize the settings.
$this->getSettings();
// Initialize the refs.
$this->getRefs($force);
return $this;
}
示例10: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $user, $language;
// In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
$emailCount = count(variable_get('drupal_test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
$this->pass($message, t('E-mail'));
}
// Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10));
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
foreach ($schema as $name => $table) {
db_drop_table($name);
}
// Get back to the original connection.
Database::removeConnection('default');
Database::renameConnection('simpletest_original_default', 'default');
// Restore original shutdown callbacks array to prevent original
// environment of calling handlers from test run.
$callbacks =& drupal_register_shutdown_function();
$callbacks = $this->originalShutdownCallbacks;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
示例11: hook_uninstall
/**
* Remove any information that the module sets.
*
* The information that the module should remove includes:
* - state that the module has set using \Drupal::state()
* - modifications to existing tables
*
* The module should not remove its entry from the module configuration.
* Database tables defined by hook_schema() will be removed automatically.
*
* The uninstall hook must be implemented in the module's .install file. It
* will fire when the module gets uninstalled but before the module's database
* tables are removed, allowing your module to query its own tables during
* this routine.
*
* @see hook_install()
* @see hook_schema()
* @see hook_modules_uninstalled()
*/
function hook_uninstall()
{
// Remove the styles directory and generated images.
file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}
示例12: tearDown
/**
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
protected function tearDown()
{
global $db_prefix, $user, $language;
// In case a fatal error occured that was not in the test process read the
// log to pick up any fatal errors.
$db_prefix_temp = $db_prefix;
$db_prefix = $this->originalPrefix;
simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE);
$db_prefix = $db_prefix_temp;
$emailCount = count(variable_get('drupal_test_email_collector', array()));
if ($emailCount) {
$message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount));
$this->pass($message, t('E-mail'));
}
if (preg_match('/simpletest\\d+/', $db_prefix)) {
// Delete temporary files directory.
file_unmanaged_delete_recursive($this->originalFileDirectory . '/simpletest/' . substr($db_prefix, 10));
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
db_drop_table($name);
}
// Return the database prefix to the original.
$db_prefix = $this->originalPrefix;
// Return the user to the original one.
$user = $this->originalUser;
drupal_save_session(TRUE);
// Ensure that internal logged in variable and cURL options are reset.
$this->loggedInUser = FALSE;
$this->additionalCurlOptions = array();
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Reset the Field API.
field_cache_clear();
// Rebuild caches.
$this->refreshVariables();
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
$this->curlClose();
}
}
示例13: restoreEnvironment
/**
* Cleans up the test environment and restores the original environment.
*
* Deletes created files, database tables, and reverts environment changes.
*
* This method needs to be invoked for both unit and integration tests.
*
* @see TestBase::prepareDatabasePrefix()
* @see TestBase::changeDatabasePrefix()
* @see TestBase::prepareEnvironment()
*/
private function restoreEnvironment()
{
// Destroy the session if one was started during the test-run.
$_SESSION = array();
if (PHP_SAPI !== 'cli' && session_status() === PHP_SESSION_ACTIVE) {
session_destroy();
$params = session_get_cookie_params();
setcookie(session_name(), '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
session_name($this->originalSessionName);
// Reset all static variables.
// Unsetting static variables will potentially invoke destruct methods,
// which might call into functions that prime statics and caches again.
// In that case, all functions are still operating on the test environment,
// which means they may need to access its filesystem and database.
drupal_static_reset();
if ($this->container && $this->container->has('state') && ($state = $this->container->get('state'))) {
$captured_emails = $state->get('system.test_mail_collector') ?: array();
$emailCount = count($captured_emails);
if ($emailCount) {
$message = $emailCount == 1 ? '1 email was sent during this test.' : $emailCount . ' emails were sent during this test.';
$this->pass($message, 'Email');
}
}
// Sleep for 50ms to allow shutdown functions and terminate events to
// complete. Further information: https://www.drupal.org/node/2194357.
usleep(50000);
// Remove all prefixed tables.
$original_connection_info = Database::getConnectionInfo('simpletest_original_default');
$original_prefix = $original_connection_info['default']['prefix']['default'];
$test_connection_info = Database::getConnectionInfo('default');
$test_prefix = $test_connection_info['default']['prefix']['default'];
if ($original_prefix != $test_prefix) {
$tables = Database::getConnection()->schema()->findTables('%');
foreach ($tables as $table) {
if (Database::getConnection()->schema()->dropTable($table)) {
unset($tables[$table]);
}
}
}
// In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors.
simpletest_log_read($this->testId, $this->databasePrefix, get_class($this));
// Restore original dependency injection container.
$this->container = $this->originalContainer;
\Drupal::setContainer($this->originalContainer);
// Delete test site directory.
file_unmanaged_delete_recursive($this->siteDirectory, array($this, 'filePreDeleteCallback'));
// Restore original database connection.
Database::removeConnection('default');
Database::renameConnection('simpletest_original_default', 'default');
// Reset all static variables.
// All destructors of statically cached objects have been invoked above;
// this second reset is guaranteed to reset everything to nothing.
drupal_static_reset();
// Restore original in-memory configuration.
$GLOBALS['config'] = $this->originalConfig;
$GLOBALS['conf'] = $this->originalConf;
new Settings($this->originalSettings);
// Restore original statics and globals.
$GLOBALS['config_directories'] = $this->originalConfigDirectories;
// Re-initialize original stream wrappers of the parent site.
// This must happen after static variables have been reset and the original
// container and $config_directories are restored, as simpletest_log_read()
// uses the public stream wrapper to locate the error.log.
$this->originalContainer->get('stream_wrapper_manager')->register();
if (isset($this->originalPrefix)) {
drupal_valid_test_ua($this->originalPrefix);
} else {
drupal_valid_test_ua(FALSE);
}
// Restore original shutdown callbacks.
$callbacks =& drupal_register_shutdown_function();
$callbacks = $this->originalShutdownCallbacks;
}
示例14: testExportWrite
/**
* @covers \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationWrite
*/
public function testExportWrite()
{
// Set a fake drupal root, so the testbot can also write into it.
vfsStream::setup('drupal');
\Drupal::getContainer()->set('app.root', 'vfs://drupal');
$package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
// Find out where package will be exported
list($full_name, $path) = $this->featuresManager->getExportInfo($package, $this->assigner->getBundle());
$path = 'vfs://drupal/' . $path . '/' . $full_name;
if (file_exists($path)) {
file_unmanaged_delete_recursive($path);
}
$this->assertFalse(file_exists($path), 'Package directory already exists.');
$this->generator->generatePackages('write', [self::PACKAGE_NAME], $this->assigner->getBundle());
$this->assertTrue(file_exists($path), 'Package directory was not generated.');
$this->assertTrue(file_exists($path . '/' . self::PACKAGE_NAME . '.info.yml'), 'Package info.yml not generated.');
$this->assertTrue(file_exists($path . '/config/install'), 'Package config/install not generated.');
$this->assertTrue(file_exists($path . '/config/install/system.site.yml'), 'Config.yml not exported.');
}
示例15: flush
/**
* {@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;
}