Copies a Workspace.

@param Workspace $workspace    - the original workspace to copy
@param Workspace $newWorkspace - the copy
@param bool      $model        - if true, the new workspace will be a model

@return Workspace
178602
public function copy(Workspace $workspace, Workspace $newWorkspace, $model = false)
    {
        $transferManager = $this->container->get('claroline.manager.workspace.transfer');

        $fileBag = new FileBag();
        //these are the new workspace datas
        $data = $transferManager->serialize($workspace);
        $data = $transferManager->exportFiles($data, $fileBag, $workspace);

        if ($this->logger) {
            $transferManager->setLogger($this->logger);
        }

        if ($newWorkspace->getCode()) {
            unset($data['code']);
        }

        if ($newWorkspace->getName()) {
            unset($data['name']);
        }

        $options = [Options::LIGHT_COPY, Options::REFRESH_UUID];
        // gets entity from raw data.
        $workspace = $transferManager->deserialize($data, $newWorkspace, $options, $fileBag);
        $workspace->setIsModel($model);

        //set the manager
        $managerRole = $this->roleManager->getManagerRole($workspace);

        if ($managerRole && $workspace->getCreator()) {
            $user = $workspace->getCreator();
            $user->addRole($managerRole);
            $this->om->persist($user);
        }

        $root = $this->resourceManager->getWorkspaceRoot($workspace);

        if ($root) {
            $this->resourceManager->createRights($root);
        }

        $this->om->persist($workspace);
        $this->om->flush();

        return $workspace;
    }
788789
protected function createContext($workspaceName)
    {
        $contextProperties = [
            'workspaceName' => $workspaceName,
            'invisibleContentShown' => true,
            'inaccessibleContentShown' => true
        ];

        return $this->contextFactory->create($contextProperties);
    }
1346667
public function copy(string $newFolderPath): self
    {
        $newFolderPath = normalize_path($newFolderPath);

        if (!is_dir($newFolderPath)) {
            $newFolder = self::create($newFolderPath);
            if ($this->copyContent($newFolder->getPath())) {
                return $newFolder;
            }
            throw new FolderException('Cannot copy folder to the new folder path ('.$newFolderPath.') for unknown reasons');
        }
        throw new FolderException('Cannot copy the folder, because a folder with the same name and path ('.$newFolderPath.') already exists',
            FolderException::ALREADY_EXIST);
    }
765729
public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
    {
        $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
        if ($existingWorkspace !== null) {
            $this->throwStatus(409, 'Workspace already exists', '');
        }

        if ($ownerAccountIdentifier !== null) {
            $owner = $this->userService->getUser($ownerAccountIdentifier);
            if ($owner === null) {
                $this->throwStatus(422, 'Requested owner account does not exist', '');
            }
        } else {
            $owner = null;
        }

        $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
        $this->workspaceRepository->add($workspace);
        $this->throwStatus(201, 'Workspace created', '');
    }
644603
public function urlSubscriptionGenerateAction(Workspace $workspace)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ( $user === 'anon.') {
            return $this->redirect(
                $this->generateUrl(
                    'claro_workspace_subscription_url_generate_anonymous',
                    array(
                        'workspace' => $workspace->getId(),
                        'toolName' => 'home'
                    )
                )
            );
        }

        $this->workspaceManager->addUserAction($workspace, $user);

        return $this->redirect(
            $this->generateUrl(
                'claro_workspace_open_tool', array('workspaceId' => $workspace->getId(), 'toolName' => 'home')
            )
        );
    }
761377
public function getUsedStorage(Workspace $workspace)
    {
        $dir = $this->getStorageDirectory($workspace);
        $size = 0;

        if (!is_dir($dir)) {
            return $size;
        }

        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)) as $file) {
            $size += $file->getSize();
        }

        return $size;
    }
1104678
public function countByWorkspace(Workspace $workspace)
    {
        $query = $this->createQuery();
        $nodesInDatabase = $query->matching($query->equals('workspace', $workspace))->execute()->count();

        $nodesInMemory = 0;
        /** @var $node NodeData */
        foreach ($this->addedNodes as $node) {
            if ($node->getWorkspace()->getName() === $workspace->getName()) {
                $nodesInMemory++;
            }
        }

        return $nodesInDatabase + $nodesInMemory;
    }
346107
public function copy($path, $newPath)
    {
        $result = $this->client->copyObject($this->bucket, $path, $this->bucket, $newPath);
        if (is_null($result)) {
            return false;
        }

        return true;
    }
134418
private function setBootstrapNamespace($oldNamespace, $newNamespace)
    {
        $files = $this->filesystem->files(base_path() . '/bootstrap');

        foreach ($files as $file) {
            $content = $this->filesystem->get($file);
            $this->filesystem->create($file, str_replace($oldNamespace . '\Controllers', $newNamespace . '\Controllers', $content));
        }
    }
1180517
public function preCopy(CopyEvent $event)
    {
        $workspace = $event->getObject();
        $options = $event->getOptions();

        $new = $event->getCopy();
        $new->refreshUuid();

        $this->manager->copy($workspace, $new, in_array(Options::WORKSPACE_MODEL, $options));
    }
327608
public function getFavouriteByWorkspaceAndUser(Workspace $workspace, User $user)
    {
        return $this->workspaceFavouriteRepo->findOneBy([
            'workspace' => $workspace,
            'user' => $user,
        ]);
    }
759387
public function publish(Workspace $targetWorkspace)
    {
        $sourceNodes = $this->publishingService->getUnpublishedNodes($this);
        $this->publishNodes($sourceNodes, $targetWorkspace);
    }
742704
public function duplicate($newPA = false)
    {
        if (!$newPA) {
            $newPA = self::create($this->pk);
        }
        $listItems = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL);
        foreach ($listItems as $li) {
            $newPA->addListItem($li->getAccessEntityObject(), $li->getPermissionDurationObject(), $li->getAccessType());
        }
        $workflows = $this->getWorkflows();
        foreach ($workflows as $wf) {
            $newPA->attachWorkflow($wf);
        }
        $newPA->setPermissionKey($this->pk);

        return $newPA;
    }
160966
public function workspaceEditFormAction(Workspace $workspace)
    {
        $user = $this->tokenStorage->getToken()->getUser();
        $this->checkAccess($workspace);
        $username = is_null($workspace->getCreator()) ? '' : $workspace->getCreator()->getUsername();
        $creationDate = is_null($workspace->getCreationDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getCreationDate()
        );
        $expDate = is_null($workspace->getEndDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getEndDate()
        );
        $count = $this->workspaceManager->countUsers($workspace, true);
        $storageUsed = $this->workspaceManager->getUsedStorage($workspace);
        $storageUsed = $this->utilities->formatFileSize($storageUsed);
        $countResources = $this->workspaceManager->countResources($workspace);
        $workspaceAdminTool = $this->toolManager->getAdminToolByName('workspace_management');
        $isAdmin = $this->authorization->isGranted('OPEN', $workspaceAdminTool);

        $form = $this->formFactory->create(
            FormFactory::TYPE_WORKSPACE_EDIT,
            array(
                $username,
                $creationDate,
                $count,
                $storageUsed,
                $countResources,
                $isAdmin,
                $expDate
            ),
            $workspace
        );

        if ($workspace->getSelfRegistration()) {
            $url = $this->router->generate(
                'claro_workspace_subscription_url_generate',
                array('workspace' => $workspace->getId()),
                true
            );
        } else {
            $url = '';
        }

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace,
            'url' => $url,
            'user' => $user,
            'count' => $count
        );
    }
723344
public function findWorkspaceRoot(Workspace $workspace)
    {
        $builder = new ResourceQueryBuilder();
        $builder->selectAsEntity()
            ->whereInWorkspace($workspace)
            ->whereParentIsNull();
        $query = $this->_em->createQuery($builder->getDql());
        $query->setParameters($builder->getParameters());

        return $query->getOneOrNullResult();
    }
369140
public function editAction(Workspace $workspace)
    {
        $this->view->assign('workspace', $workspace);
        $this->view->assign('baseWorkspaceOptions', $this->prepareBaseWorkspaceOptions($workspace));
        $this->view->assign('disableBaseWorkspaceSelector', $this->publishingService->getUnpublishedNodesCount($workspace) > 0);
        $this->view->assign('showOwnerSelector', $this->userService->currentUserCanTransferOwnershipOfWorkspace($workspace));
        $this->view->assign('ownerOptions', $this->prepareOwnerOptions());
    }
561036
public function configureModelAction(WorkspaceModel $model)
    {
        $resourceModels = $model->getResourcesModel();
        $copied = [];
        $links = [];

        foreach ($resourceModels as $resourceModel) {
            $resourceModel->isCopy() ? $copied[] = $resourceModel: $links[] = $resourceModel;
        }

        $root = $this->resourceManager->getWorkspaceRoot($model->getWorkspace());

        return array(
            'model'  => $model,
            'copied' => $copied,
            'links'  => $links,
            'rootId' => $root->getId(),
            'workspace' => $model->getWorkspace()
        );
    }