Rename file, if it in the temp folder.

@param EntityInterface $entity
@param string $target
16543
protected function renameFile(EntityInterface $entity, $target)
    {
        if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) {
            $filename = $entity->getFilename();
            $entity->setFilename($target.pathinfo($filename, PATHINFO_BASENAME));
            $root = $this->root.$entity->getDownloadPath().'/';
            $this->fs->copy($root.$filename, $root.$entity->getFilename(), true);
        }
    }
365409
public function updateTarget(Target $target): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_rule_target')
            ->set('rule_id', ':rule_id')
            ->set('type', ':type')
            ->set('value', ':value')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $target->id, Type::INTEGER)
            ->setParameter('rule_id', $target->ruleId, Type::INTEGER)
            ->setParameter('type', $target->type, Type::STRING)
            ->setParameter('value', $target->value, is_array($target->value) ? Type::JSON_ARRAY : Type::STRING);

        $this->applyStatusCondition($query, $target->status);

        $query->execute();
    }
317386
public function updateEntity(EntityInterface $entity)
    {
        $update = $this->getSql()->update();
        $update->set($this->getHydrator()->extract($entity));
        $update->where->equalTo($this->getPrimaryKey(), $entity->getIdentifier());

        try {
            $this->updateWith($update);
        } catch (RuntimeException $e) {
            return false;
        }

        return true;
    }
785184
public static function renameFolder( $sourceFolder, $targetName )
	{
		$targetName	= basename( $targetName );
		if( !self::isFolder( $sourceFolder ) )												//  Source Folder not existing
			throw new RuntimeException( 'Folder "'.$sourceFolder.'" is not existing' );

		$sourcePath	= self::correctPath( dirname( $sourceFolder ) );						//  Path to Source Folder
		if( basename( $sourceFolder ) == $targetName )										//  Source Name and Target name is equal
			return FALSE;
		if( self::isFolder( $sourcePath.$targetName ) )										//  Target Folder is already existing
			throw new RuntimeException( 'Folder "'.$sourcePath.$targetName.'" is already existing' );
		if( FALSE === @rename( $sourceFolder, $sourcePath.$targetName ) )					//  rename Source Folder to Target Folder
			throw new RuntimeException( 'Folder "'.$sourceFolder.'" cannot be renamed to "'.$sourcePath.$targetName.'"' );
		return TRUE;
	}
1073920
private function copy($source, $target)
    {
        $files = $this->listFiles($source, $target);

        foreach ($files as $newPath => $oldPath) {
            if (!file_exists($newPath)) {
                if (is_dir($oldPath)) {
                    mkdir($newPath, 0755, true);
                } else {
                    copy($oldPath, $newPath);
                }
            }
        }
    }
1245004
public function afterSave(Event $event, EntityInterface $entity) {
		if ($this->getConfig('uploadOn') === 'afterSave') {
			$this->_handleFiles($entity);
		}
	}
279039
public function copy($target) {
        if (!parent::copy($target))
            return false;
        return copy($this->fileSource, $target);
    }
628773
public function update(\Composer\Repository\InstalledRepositoryInterface $repo, \Composer\Package\PackageInterface $initial,
			\Composer\Package\PackageInterface $target) {
				
		$this->moveBackResources($initial);
		
		parent::update($repo, $initial, $target);
		
		$this->removeResources($target);
		$this->installResources($target);
	}
1097431
public function copy($source, $target)
    {
        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);

        if (!file_exists($target)) {
            mkdir($target, 0777, true);
        }

        foreach ($ri as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
            if ($file->isDir()) {
                if (!file_exists($targetPath)) {
                    mkdir($targetPath);
                }
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
1031482
public function afterDelete(Event $event, Entity $entity) {
        // configuration set?
        $this->check();

        // delete existing files linked to this entity
        foreach($this->_config['fields'] as $field => $path)
            $this->deleteFile($entity->get($field));
    }
1095066
public function move(FileAbstraction $entity, $target = null)
	{
		$entityManager = $this->getDoctrineEntityManager();
		$entityManager->beginTransaction();

		try {
			// move entity in database
			$entityManager->persist($entity);

			$otherStorageOldPath = null;
			if ($entity instanceof Folder) {
				if ($entity->isPublic()) {
					$otherStorageOldPath = $this->getFilesystemPath($entity, true, self::FILE_INFO_INTERNAL);
				} else {
					$otherStorageOldPath = $this->getFilesystemPath($entity, true, self::FILE_INFO_EXTERNAL);
				}
			}

			$oldPath = $this->getFilesystemPath($entity);

			if ($target instanceof Folder) {
				$entity->moveAsLastChildOf($target);
			} else {
				$rootLevelFolder = $entityManager->getRepository(FileAbstraction::CN())
						->findOneBy(array('level' => 0));

				if ( ! $rootLevelFolder instanceof FileAbstraction) {
					throw new Exception\RuntimeException('Failed to find root level file');
				}

				$entity->moveAsNextSiblingOf($rootLevelFolder);
			}

			$entityManager->flush();


			$otherStorageNewPath = null;
			if ($entity instanceof Folder) {
				if ($entity->isPublic()) {
					$otherStorageNewPath = $this->getFilesystemPath($entity, true, self::FILE_INFO_INTERNAL);
				} else {
					$otherStorageNewPath = $this->getFilesystemPath($entity, true, self::FILE_INFO_EXTERNAL);
				}
			}

			$newPath = $this->getFilesystemPath($entity);

			if ( ! rename($oldPath, $newPath)) {
				if ($entity instanceof Folder) {
					$this->log()->error("Failed to move '{$oldPath}' to '{$newPath}' in filesystem");
					$this->createFolderInFileSystem($newPath);
				} else {
					throw new Exception\RuntimeException('Failed to move in filesystem');
				}
			}

			// move file/folder from opposite storage in  file system
			if ($entity instanceof Folder) {
				if ( ! rename($otherStorageOldPath, $otherStorageNewPath)) {
					$this->log()->error("Failed to move folder from '{$otherStorageOldPath}' to '{$otherStorageNewPath}' in filesystem");
					$this->createFolderInFileSystem($otherStorageNewPath);
					//throw new Exception\RuntimeException('Failed to move in filesystem');
				}
			}

			$entityManager->commit();
		} catch (\Exception $e) {
			$entityManager->rollback();
			throw $e;
		}

		// return entity back
		return $entity;
	}
172363
protected function triggerDelete(
        EntityInterface $entity, $action = Delete::ACTION_BEFORE_DELETE
    ) {
        $event = new Delete($entity);
        $event->setAction($action);
        return Orm::getEmitter($this->getEntityClassName())
            ->emit($event);
    }
590379
public function afterSave(Event $event, EntityInterface $entity)
    {
        $property = $this->versionAssociation()->getProperty();
        $entity->unsetProperty($property);
    }
779560
public function copyFile($source, $target, $file)
    {
        $this->mkDir($target);
        if (file_exists($source.$file)) {
            copy($source.$file, $target.$file);
        }
    }
959821
private function copyThenRemove($source, $target)
    {
        if (!is_dir($source)) {
            copy($source, $target);
            $this->unlink($source);

            return;
        }

        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
        $this->ensureDirectoryExists($target);

        foreach ($ri as $file) {
            $targetPath = $target.DIRECTORY_SEPARATOR.$ri->getSubPathName();
            if ($file->isDir()) {
                $this->ensureDirectoryExists($targetPath);
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }

        $this->removeDirectoryPhp($source);
    }
158175
private function copyRecursive($source, $target)
    {
        if (!is_dir($source)) {
            $this->filesystem->ensureDirectoryExists(dirname($target));
            copy($source, $target);

            return;
        }

        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        $this->filesystem->ensureDirectoryExists($target);

        foreach ($iterator as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
            if ($file->isDir()) {
                $this->filesystem->ensureDirectoryExists($targetPath);
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
178181
public static function move($source, $target)
    {
        if (!file_exists($source) || !is_dir($source)) {
            // Rename fails if source folder does not exist.
            throw new \RuntimeException('Cannot move non-existing folder.');
        }

        // Don't do anything if the source is the same as the new target
        if ($source === $target) {
            return;
        }

        if (file_exists($target)) {
            // Rename fails if target folder exists.
            throw new \RuntimeException('Cannot move files to existing folder/file.');
        }

        // Make sure that path to the target exists before moving.
        self::create(dirname($target));

        // Silence warnings (chmod failed etc).
        @rename($source, $target);

        // Rename function can fail while still succeeding, so let's check if the folder exists.
        if (!file_exists($target) || !is_dir($target)) {
            // In some rare cases rename() creates file, not a folder. Get rid of it.
            if (file_exists($target)) {
                @unlink($target);
            }
            // Rename doesn't support moving folders across filesystems. Use copy instead.
            self::copy($source, $target);
            self::delete($source);
        }

        // Make sure that the change will be detected when caching.
        @touch(dirname($source));
        @touch(dirname($target));
        @touch($target);
    }