Change the owner of an array of files.

@param (string) $source Name of file or directory with path.
@param (array)  $files  Files to be copy.
@param (mixed)  $user   The new owner user name.

@since 3.0.0

@return bool
7696
public function chown($source, $files, $user)
    {
        foreach ($files as $file => $value) {
            if (file_exists($source.$value)) {
                @chown($file, $user);
            }
        }
    }
1278258
public function setOwner(\WobbleCode\UserBundle\Document\User $owner)
    {
        $this->owner = $owner;
        return $this;
    }
1175401
public function copy($target, $source)
    {
        if (!$this->exists($target)) {
            throw new \RuntimeException("$target does not exist.", E_ERROR);
        }

        if (!$this->exists($source)) {
            $this->makeDirectory(dirname($source), true);
        }

        return file_put_contents($source, $this->get($target));
    }
1298195
public function toggleFavourites(User $user, array $resourceNodes)
    {
        if (0 < count($resourceNodes)) {
            $firstFavourite = $this->repo->findOneBy(['user' => $user, 'resourceNode' => $resourceNodes[0]]);
            $mode = empty($firstFavourite) ? 'create' : 'delete';

            $this->om->startFlushSuite();

            switch ($mode) {
                case 'create':
                    foreach ($resourceNodes as $resourceNode) {
                        $this->createFavourite($user, $resourceNode);
                    }
                    break;
                case 'delete':
                    foreach ($resourceNodes as $resourceNode) {
                        $this->deleteFavourite($user, $resourceNode);
                    }
                    break;
            }
            $this->om->endFlushSuite();
        }
    }
1102963
public function updateAddress(array $data, $user)
    {
        $this->getEventManager()->trigger('updateInfo.pre', $this, array('user' => $user, 'data' => $data));

        $form  = $this->getServiceManager()->get('playgrounduser_address_form');
        $form->bind($user);
        $form->setData($data);

        $filter = $user->getInputFilter();
        $filter->remove('password');
        $filter->remove('passwordVerify');
        $filter->remove('dob');

        $form->setInputFilter($filter);

        if ($form->isValid()) {
            $user = $this->getUserMapper()->update($user);
            $this->getEventManager()->trigger('updateInfo.post', $this, array('user' => $user, 'data' => $data));

            if ($user) {
                return $user;
            }
        }

        return false;
    }
1219393
public function replaceUser(User $from, User $to)
    {
        $pdfs = $this->repo->findByCreator($from);

        if (count($pdfs) > 0) {
            foreach ($pdfs as $pdf) {
                $pdf->setCreator($to);
            }

            $this->om->flush();
        }

        return count($pdfs);
    }
144841
public function changeOwner( $userName, $recursive = FALSE )
	{
		if( !$userName )
			throw new InvalidArgumentException( 'User missing' );
		$number	= (int) chown( $this->folderName, $userName );

		if( !$recursive )
			return $number;
		$iterator = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator( $this->folderName ),
			RecursiveIteratorIterator::SELF_FIRST
		);
		foreach( $iterator as $item )
			$number += (int) chown( $item, $userName );
		return $number;
	}
1061449
public function setNewActiveContributionToSection(User $user = null)
    {
        $oldActiveContribution = $this->getActiveContribution();
        $newActiveContribution = new Contribution();
        $newActiveContribution->setSection($this);
        if (null === $oldActiveContribution) {
            if (null === $user) {
                $user = $this->getAuthor();
            }
        } else {
            if (null === $user) {
                $user = $oldActiveContribution->getContributor();
            }
            if (null === $user) {
                $user = $this->getAuthor();
            }
            $newActiveContribution->setTitle($oldActiveContribution->getTitle());
            $newActiveContribution->setText($oldActiveContribution->getText());
        }
        $newActiveContribution->setContributor($user);
        $this->setActiveContribution($newActiveContribution);
    }
512680
public function rename(User $user, $username)
    {
        $userRole = $this->roleManager->getUserRoleByUser($user);
        if ($userRole) $this->roleManager->renameUserRole($userRole, $user->getUsername());
        $user->setUsername($username);
        $personalWorkspaceName = $this->translator->trans('personal_workspace', array(), 'platform') . $user->getUsername();
        $pws = $user->getPersonalWorkspace();
        if ($pws) $this->workspaceManager->rename($pws, $personalWorkspaceName);
        $this->objectManager->persist($user);
        $this->objectManager->flush();
    }
497720
public function move(Config $source) {
		$files = $_FILES[$source->defaultFilesKey];
		/**
		 * @var $output File[]
		 */
		$output = [];

		try {
			if (isset($files) and is_array($files) and isset($files['name']) and is_array($files['name']) and count($files['name'])) {
				foreach ($files['name'] as $i => $file) {
					if ($files['error'][$i]) {
						throw new \Exception(isset(Helper::$upload_errors[$files['error'][$i]]) ? Helper::$upload_errors[$files['error'][$i]] : 'Error', $files['error'][$i]);
					}

					$path     = $source->getPath();
					$tmp_name = $files['tmp_name'][$i];
					$new_path = $path . Helper::makeSafe($files['name'][$i]);

					if (!move_uploaded_file($tmp_name, $new_path)) {
						if (!is_writable($path)) {
							throw new \Exception('Destination directory is not writeble', Consts::ERROR_CODE_IS_NOT_WRITEBLE);
						}

						throw new \Exception('No files have been uploaded', Consts::ERROR_CODE_NO_FILES_UPLOADED);
					}

					$file = new File($new_path);

					try {
						$this->accessControl->checkPermission($this->getUserRole(), $this->action, $source->getRoot(), pathinfo($file->getPath(), PATHINFO_EXTENSION));
					} catch (\Exception $e) {
						$file->remove();
						throw $e;
					}

					if (!$file->isGoodFile($source)) {
						$file->remove();
						throw new \Exception('File type is not in white list', Consts::ERROR_CODE_FORBIDDEN);
					}

					if ($source->maxFileSize and $file->getSize() > Helper::convertToBytes($source->maxFileSize)) {
						$file->remove();
						throw new \Exception('File size exceeds the allowable', Consts::ERROR_CODE_FORBIDDEN);
					}

					$output[] = $file;
				}
			}
		} catch (\Exception $e) {
			foreach ($output as $file) {
				$file->remove();
			}
			throw $e;
		}

		return $output;
	}
1322616
public function isOwner(User $user)
    {
        $owner = $this->getOwner();
        if ($owner !== null && $user->getId() === $owner->getUser()->getId()) {
            return true;
        }

        return false;
    }
127571
public function copyDirectory(string $source, string $target, int $flags = null) : bool
    {
        if (!$this->exists($source)) {
            return false;
        }

        if (!$this->isDirectory($target) && !$this->makeDirectory($target, 0777, true)) {
            return false;
        }

        if ($flags === null) {
            $flags = FilesystemIterator::SKIP_DOTS;
        }

        $items = new FilesystemIterator($source, $flags);

        foreach ($items as $item) {
            if ($item->isDir()) {
                if (!$this->copyDirectory($item->getRealPath(), $target . '/' . $item->getBasename(), $flags)) {
                    return false;
                }
            } elseif ($item->isFile()) {
                if (!$this->copyFile($item->getRealPath(), $target . '/' . $item->getBasename())) {
                    return false;
                }
            }
        }

        return true;
    }
245006
public function setUser($user)
    {
        if ($user instanceof User) {
            $this->_user = $user;
            return true;
        }
        $this->_user = null;
        return false;
    }
577317
public function replaceUser(User $from, User $to)
    {
        $shareds = $this->om->getRepository('UJMExoBundle:Item\Shared')->findByUser($from);

        if (count($shareds) > 0) {
            foreach ($shareds as $shared) {
                $shared->setUser($to);
            }

            $this->om->flush();
        }

        return count($shareds);
    }
941134
public static function chown($path, $user, $group = null)
    {

        // don't do anything under Windows
        if (FileSystem::getOsIdentifier() === self::OS_IDENTIFIER_WIN) {
            return;
        }

        // check if the path exists
        if (!file_exists($path)) {
            return false;
        }

        // change the owner
        if (chown($path, $user) === false) {
            throw new \Exception(sprintf('Can\'t change owner for directory/flie %s to %s', $path, $user));
        }

        // check if group is given too
        if (!is_null($group)) {
            if (chgrp($path, $group) === false) {
                throw new \Exception(sprintf('Can\'t change group for directory/flie %s to %s', $path, $group));
            }
        }

        return true;
    }
178142
public function set_user($user)
    {
        if (is_object($user)) {
            $this->user = $user;

            // overwrite config with user preferences
            $this->config->set_user_prefs((array)$this->user->get_prefs());
        }
    }
1072034
public function copy($source, $target) {
        // using mark.
        if ('@' == $source[0]) $source = $this->as($source);
        if ('@' == $target[0]) $target = $this->as($target);

        // copy file.
        if (is_file($source)) return copy($source, $target);

        // copy directory.
        $handle = opendir($source);
        while (false !== ($name = readdir($handle))) {
            if ('.' == $name or '..' == $name) continue;
            $subsource = $source.self::DS.$name;
            $subtarget = $target.self::DS.$name;
            if (!$this->copy($subsource, $subtarget)) return false;
        }
        closedir($handle);
        return true;
    }