rename example

// Ensure compatibility with Windows.     // @see \Drupal\Core\File\FileSystemInterface::unlink().     if (!$this->streamWrapperManager->isValidUri($source) && (substr(PHP_OS, 0, 3) == 'WIN')) {
      chmod($source, 0600);
    }
    // Attempt to resolve the URIs. This is necessary in certain     // configurations (see above) and can also permit fast moves across local     // schemes.     $real_source = $this->realpath($source) ?: $source;
    $real_destination = $this->realpath($destination) ?: $destination;
    // Perform the move operation.     if (!@rename($real_source$real_destination)) {
      // Fall back to slow copy and unlink procedure. This is necessary for       // renames across schemes that are not local, or where rename() has not       // been implemented. It's not necessary to use FileSystem::unlink() as the       // Windows issue has already been resolved above.       if (!@copy($real_source$real_destination)) {
        $this->logger->error("The specified file '%source' could not be moved to '%destination'.", [
          '%source' => $source,
          '%destination' => $destination,
        ]);
        throw new FileWriteException("The specified file '$source' could not be moved to '$destination'.");
      }
      
    if ($this->storage instanceof StorageCacheInterface) {
      $this->storage->resetListCache();
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function rename($old_name$new_name) {
    Cache::invalidateTags($this->get($old_name)->getCacheTags());
    $this->storage->rename($old_name$new_name);

    // Clear out the static cache of any references to the old name.     foreach ($this->getConfigCacheKeys($old_name) as $old_cache_key) {
      unset($this->cache[$old_cache_key]);
    }

    // Prime the cache and load the configuration with the correct overrides.     $config = $this->get($new_name);
    $this->eventDispatcher->dispatch(new ConfigRenameEvent($config$old_name), ConfigEvents::RENAME);
    return $this;
  }

  
pathinfo($filename, \PATHINFO_FILENAME),
            'return ' . $timestamp . ';',
        ];

        $replace = [
            str_replace($timestamp$newTimestamp$className),
            'return ' . $newTimestamp . ';',
        ];

        $this->updateMigrationFile($path$search$replace);

        rename($path$newPath);

        return self::SUCCESS;
    }

    private function getCurrentTimestamp(string $filename): string
    {
        if (!preg_match('#Migration([\d]+).*?\.php#i', $filename$matches)) {
            throw new \RuntimeException('Could not determine current timestamp.');
        }

        return $matches[1];
    }

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->randomkey(...\func_get_args());
    }

    public function rawcommand($cmd, ...$args)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rawcommand(...\func_get_args());
    }

    public function rename($key$newkey)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rename(...\func_get_args());
    }

    public function renamenx($key$newkey)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->renamenx(...\func_get_args());
    }

    public function restore($ttl$key$value)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->restore(...\func_get_args());
    }

    
foreach ($shops as $shop) {
            $oldTimestamp = (int) $compiler->getThemeTimestamp($shop);
            if ($oldTimestamp === $time) {
                ++$time;
            }

            $new = $pathResolver->getCssFilePath($shop, 'new');
            if (!file_exists($new)) {
                continue;
            }

            rename(
                $pathResolver->getCssFilePath($shop, 'new'),
                $pathResolver->getCssFilePath($shop$time)
            );

            rename(
                $pathResolver->getJsFilePath($shop, 'new'),
                $pathResolver->getJsFilePath($shop$time)
            );

            $compiler->clearThemeCache($shop$oldTimestamp);
            $compiler->createThemeTimestamp($shop$time);
        }
public function move( $source$destination$overwrite = false ) {
        if ( ! $overwrite && $this->exists( $destination ) ) {
            return false;
        }

        if ( $overwrite && $this->exists( $destination ) && ! $this->delete( $destination, true ) ) {
            // Can't overwrite if the destination couldn't be deleted.             return false;
        }

        // Try using rename first. if that fails (for example, source is read only) try copy.         if ( @rename( $source$destination ) ) {
            return true;
        }

        // Backward compatibility: Only fall back to `::copy()` for single files.         if ( $this->is_file( $source ) && $this->copy( $source$destination$overwrite ) && $this->exists( $destination ) ) {
            $this->delete( $source );

            return true;
        } else {
            return false;
        }
    }
if (!$dryRun) {
            $this->filesystem->mkdir($releaseDir);
            $output[] = '* Move the unreleased changelog files to release folder: ' . $releaseDir;
        } else {
            $output[] = '---';
            $output[] = 'Move the unreleased changelog files to release folder: ' . $releaseDir;
            $output[] = '---';
        }

        foreach ($collection as $changelog) {
            if (!$dryRun) {
                $this->filesystem->rename($this->getUnreleasedDir() . '/' . $changelog->getName()$releaseDir . '/' . $changelog->getName());
            } else {
                $output[] = '* ' . $changelog->getName();
            }
        }

        return $output;
    }

    /** * Update the CHANGELOG.md global file * * @param list<string> $output * * @return list<string> */

  protected function doSave($id, EntityInterface $entity) {
    $is_new = $entity->isNew();
    $prefix = $this->getPrefix();
    $config_name = $prefix . $entity->id();
    if ($id !== $entity->id()) {
      // Renaming a config object needs to cater for:       // - Storage needs to access the original object.       // - The object needs to be renamed/copied in ConfigFactory and reloaded.       // - All instances of the object need to be renamed.       $this->configFactory->rename($prefix . $id$config_name);
    }
    $config = $this->configFactory->getEditable($config_name);

    // Retrieve the desired properties and set them in config.     $config->setData($this->mapToStorageRecord($entity));
    $config->save($entity->hasTrustedData());

    // Update the entity with the values stored in configuration. It is possible     // that configuration schema has casted some of the values.     if (!$entity->hasTrustedData()) {
      $data = $this->mapFromStorageRecords([$config->get()]);
      
$config_object->save(FALSE)
      ->shouldBeCalled();
    $config_object->get()->willReturn([]);

    $this->cacheTagsInvalidator->invalidateTags([$this->entityTypeId . '_list'])
      ->shouldBeCalled();

    $this->configFactory->get('the_provider.the_config_prefix.foo')
      ->willReturn($immutable_config_object->reveal());
    $this->configFactory->loadMultiple(['the_provider.the_config_prefix.foo'])
      ->willReturn([]);
    $this->configFactory->rename('the_provider.the_config_prefix.foo', 'the_provider.the_config_prefix.bar')
      ->shouldBeCalled();
    $this->configFactory->getEditable('the_provider.the_config_prefix.bar')
      ->willReturn($config_object->reveal());

    // Performing a rename does not change the original ID until saving.     $this->assertSame('foo', $entity->getOriginalId());
    $entity->set('id', 'bar');
    $this->assertSame('foo', $entity->getOriginalId());

    $this->entityQuery->condition('uuid', 'bar')->willReturn($this->entityQuery);
    $this->entityQuery->execute()->willReturn([$entity->id()]);

    
return $this->storage->delete($name);
  }

  /** * {@inheritdoc} */
  public function rename($name$new_name) {
    if (isset($this->replacementData[$this->collection][$name])) {
      $this->replacementData[$this->collection][$new_name] = $this->replacementData[$this->collection][$name];
      unset($this->replacementData[$this->collection][$name]);
    }
    return $this->storage->rename($name$new_name);
  }

  /** * {@inheritdoc} */
  public function encode($data) {
    return $this->storage->encode($data);
  }

  /** * {@inheritdoc} */
->save();
    \Drupal::languageManager()
      ->getLanguageConfigOverride('fr', 'config_test.foo')
      ->set('value', ['key' => 'override'])
      ->save();
    \Drupal::configFactory()->clearStaticCache();
    $config = \Drupal::config('config_test.foo');
    $this->assertSame(['key' => 'override']$config->get('value'));

    // Ensure renaming the config will rename the override.     \Drupal::languageManager()->setConfigOverrideLanguage(\Drupal::languageManager()->getLanguage('en'));
    \Drupal::configFactory()->rename('config_test.foo', 'config_test.bar');
    $config = \Drupal::config('config_test.bar');
    $this->assertEquals(['key' => 'original']$config->get('value'));
    $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.foo');
    $this->assertTrue($override->isNew());
    $this->assertNull($override->get('value'));
    $override = \Drupal::languageManager()->getLanguageConfigOverride('de', 'config_test.bar');
    $this->assertFalse($override->isNew());
    $this->assertEquals(['key' => 'override']$override->get('value'));
    $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'config_test.bar');
    $this->assertFalse($override->isNew());
    $this->assertEquals(['key' => 'override']$override->get('value'));

    
if (false === @mkdir($dir, 0777, true)) {
                clearstatcache(true, $dir);
                if (!is_dir($dir)) {
                    throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
                }
            }
        } elseif (!is_writable($dir)) {
            throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
        }

        $tmpFile = tempnam($dirbasename($key));
        if (false !== @file_put_contents($tmpFile$content) && @rename($tmpFile$key)) {
            @chmod($key, 0666 & ~umask());

            if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
                // Compile cached file into bytecode cache                 if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
                    @opcache_invalidate($key, true);
                } elseif (\function_exists('apc_compile_file')) {
                    apc_compile_file($key);
                }
            }

            
$new->getName()]$new->getRawData()],
      ]);

    $this->cacheTagsInvalidator->expects($this->once())
      ->method('invalidateTags')
      ->with($old->getCacheTags());

    $this->storage->expects($this->once())
      ->method('rename')
      ->with($old->getName()$new->getName());

    $this->configFactory->rename($old->getName()$new->getName());
  }

}

        $this->validateActive();

        if (false === $this->isStringNotEmpty($targetPath)) {
            throw new InvalidArgumentException(
                'Invalid path provided for move operation; must be a non-empty string'
            );
        }

        if ($this->file) {
            $this->moved = PHP_SAPI === 'cli'
                ? rename($this->file, $targetPath)
                : move_uploaded_file($this->file, $targetPath);
        } else {
            Utils::copyToStream(
                $this->getStream(),
                new LazyOpenStream($targetPath, 'w')
            );

            $this->moved = true;
        }

        if (false === $this->moved) {
            
try {
            $archive->extractTo($destination);

            if ($backupFile !== null) {
                $this->filesystem->remove($backupFile);
            }

            if ($delete) {
                unlink($archive->filename);
            }
        } catch (\Exception $e) {
            $this->filesystem->rename($backupFile$oldFile);

            throw $e;
        }

        $this->clearOpcodeCache();

        $archive->close();
    }

    /** * Iterates all files of the provided zip archive * path and validates the plugin namespace, directory traversal * and multiple plugin directories. */
Home | Imprint | This part of the site doesn't use cookies.