/** * Make template * * @return void **/ protected function make() { if (count($this->templateFiles) > 0) { foreach ($this->templateFiles as $template) { if (is_dir($template['path'])) { if (!Filesystem::copyDirectory($template['path'], $template['destination'])) { $this->output->error("Error: an problem occured copying {$template['path']} to {$template['destination']}."); } // Get folder contents $this->scanFolder($template['destination']); } elseif (is_file($template['path'])) { if (!copy($template['path'], $template['destination'])) { $this->output->error("Error: an problem occured copying {$template['path']} to {$template['destination']}."); } // Get template contents $contents = file_get_contents($template['destination']); $contents = $this->doReplacements($contents); // Write file $this->putContents($template['destination'], $contents); } } } }
/** * Method to check if new template name already exists * * @return boolean true if name is not used, false otherwise * @since 2.5 */ public function copy() { if ($template = $this->getTemplate()) { $client = JApplicationHelper::getClientInfo($template->client_id); $fromPath = Filesystem::cleanPath($client->path . '/templates/' . $template->element . '/'); // Delete new folder if it exists $toPath = $this->getState('to_path'); if (Filesystem::exists($toPath)) { if (!Filesystem::deleteDirectory($toPath)) { Notify::warning(Lang::txt('COM_TEMPLATES_ERROR_COULD_NOT_WRITE')); return false; } } // Copy all files from $fromName template to $newName folder if (!Filesystem::copyDirectory($fromPath, $toPath) || !$this->fixTemplateName()) { return false; } return true; } else { Notify::warning(Lang::txt('COM_TEMPLATES_ERROR_INVALID_FROM_NAME')); return false; } }
/** * Copy existing form and data to new form * * @return mixed **/ public function copy() { $title = $this->getTitle(); $questions = $this->getPageLayout(); $oldId = $this->getId(); // Save new $this->id = null; $id = $this->getId(); $this->setTitle($title); $base = $this->base . $oldId; // Copy actual files if (is_dir($base)) { // Scan for versions $versions = array(); $dirs = scandir($base); foreach ($dirs as $dir) { if (is_numeric($dir) && is_dir($base . DS . $dir) && $dir != '.' && $dir != '..') { $versions[] = $dir; } } if (!empty($versions)) { $base .= DS . max($versions); } \Filesystem::copyDirectory($base, $this->base . $id); } // Copy questions $this->setPageLayout($questions); // Copy deployment (only most recent) try { $dep = PdfFormDeployment::latestFromFormId($oldId); $dep->setId(null); $dep->setFormId($id); $dep->genNewCrumb(); $dep->save(); // Return the deployment crumb return $dep->getCrumb(); } catch (\Hubzero\Error\Exception\RuntimeException $e) { // Just return the form id return $id; } }
/** * Transfer files from one version to another * * @param string $sourceid Source version ID * @param string $destid Destination version ID * @param integer $rid Resource ID * @return boolean False if errors, True on success */ public function transfer($sourceid, $destid, $rid) { Log::debug(__FUNCTION__ . '()'); // Get resource information $resource = new \Components\Resources\Tables\Resource($this->database); $resource->load($rid); // Get screenshot information $ss = new \Components\Resources\Tables\Screenshot($this->database); $shots = $ss->getFiles($rid, $sourceid); // Build the path include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; $listdir = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, ''); $srcdir = $listdir . DS . $sourceid; $destdir = $listdir . DS . $destid; $src = $this->_buildUploadPath($srcdir, ''); $dest = $this->_buildUploadPath($destdir, ''); // Make sure the path exist if (!is_dir($src)) { if (!Filesystem::makeDirectory($src)) { $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH')); return false; } } Log::debug(__FUNCTION__ . "() {$src}"); // do we have files to transfer? $files = Filesystem::files($src, '.', false, true, array()); Log::debug(__FUNCTION__ . "() " . implode(',', $files)); if (!empty($files)) { // Copy directory Log::debug(__FUNCTION__ . "() copying {$src} to {$dest}"); if (!Filesystem::copyDirectory($src, $dest, '', true)) { return false; } else { // Update screenshot information for this resource $ss->updateFiles($rid, $sourceid, $destid, $copy = 1); Log::debug(__FUNCTION__ . '() updated files'); return true; } } Log::debug(__FUNCTION__ . '() done'); return true; }
/** * Prep file directory (provisioned project) * * @param boolean $force * * @return boolean */ protected function _prepDir($force = true) { if (!$this->model->exists()) { $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH')); return; } // Get member files path $memberPath = $this->_getMemberPath(); // Create and initialize local repo if (!$this->model->repo()->iniLocal()) { $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH')); return; } // Copy files from member directory if (!Filesystem::copyDirectory($memberPath, $this->model->repo()->get('path'))) { $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES')); return false; } // Read copied files $get = Filesystem::files($this->model->repo()->get('path')); $num = count($get); $checkedin = 0; // Check-in copied files if ($get) { foreach ($get as $file) { $file = str_replace($this->model->repo()->get('path') . DS, '', $file); if (is_file($this->model->repo()->get('path') . DS . $file)) { // Checkin into repo $this->model->repo()->call('checkin', array('file' => $this->model->repo()->getMetadata($file, 'file', array()))); $checkedin++; } } } if ($num == $checkedin) { // Clean up member files Filesystem::deleteDirectory($memberPath); return true; } return false; }
/** * Activate provisioned project * * @return void */ public function activateTask() { // Cannot proceed without project id/alias if (!$this->model->exists()) { throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404); return; } // Must be project creator if (!$this->model->access('owner')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Must be a provisioned project to be activated if (!$this->model->isProvisioned()) { // Redirect to project page App::redirect(Route::url($this->model->link())); return; } // Redirect to setup if activation not complete if ($this->model->inSetup()) { App::redirect(Route::url($this->model->link('setup'))); return; } // Get publication of a provisioned project $pub = $this->model->getPublication(); if (empty($pub)) { throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404); return; } // Incoming $name = trim(Request::getVar('new-alias', '', 'post')); $title = trim(Request::getVar('title', '', 'post')); $confirm = trim(Request::getInt('confirm', 0, 'post')); $name = preg_replace('/ /', '', $name); $name = strtolower($name); // Check incoming data $verified = $this->model->check($name, $this->model->get('id')); if ($confirm && !$verified) { $error = $this->model->getError() ? $this->model->getError() : Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY'); $this->setError($error); } elseif ($confirm && ($title == '' || strlen($title) < 3)) { $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY')); } // Set the pathway $this->_buildPathway(); // Set the page title $this->_buildTitle(); // Display page if (!$confirm || $this->getError()) { $this->view->setLayout('provisioned'); $this->view->model = $this->model; $this->view->team = $this->model->_tblOwner->getOwnerNames($this->model->get('alias')); // Output HTML $this->view->pub = isset($pub) ? $pub : ''; $this->view->suggested = $name; $this->view->verified = $verified; $this->view->suggested = $verified ? $this->view->suggested : ''; $this->view->title = $this->title; $this->view->active = $this->active; $this->view->task = $this->_task; $this->view->authorized = 1; $this->view->option = $this->_option; $this->view->msg = $this->_getNotifications('success'); if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->display(); return; } // Save new alias & title if (!$this->getError()) { $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250)); $this->model->set('alias', $name); $state = $this->_setupComplete == 3 ? 0 : 1; $this->model->set('state', $state); $this->model->set('setup_stage', 2); $this->model->set('provisioned', 0); $this->model->set('modified', Date::toSql()); $this->model->set('modified_by', User::get('id')); // Save changes if (!$this->model->store()) { $this->setError($this->model->getError()); } } // Get project parent directory $path = Helpers\Html::getProjectRepoPath($this->model->get('alias')); $newpath = Helpers\Html::getProjectRepoPath($name, 'files', true); // Rename project parent directory if ($path && is_dir($path)) { if (!Filesystem::copyDirectory($path, $newpath)) { $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES')); } else { // Correct permissions to 0755 Filesystem::setPermissions($newpath); // Delete original repo Filesystem::deleteDirectory($path); } } // Log activity $this->_logActivity($this->model->get('id'), 'provisioned', 'activate', 'save', 1); // Send to continue setup App::redirect(Route::url($this->model->link('setup'))); return; }