Setup/configure the application.
More...
List of all members.
Detailed Description
Setup/configure the application.
- Copyright:
- 2011-2012 Perforce Software. All rights reserved
- License:
- Please see LICENSE.txt in top-level folder of this distribution.
- Version:
- 2012.2/486814
Member Function Documentation
Setup_IndexController::_cleanupSession |
( |
| ) |
[protected] |
Clear out completed setup data from session.
{
$session = $this->_getSession();
if ($session->setupComplete) {
$session->site = null;
$session->storage = null;
$session->administrator = null;
$session->setupComplete = false;
}
}
Setup_IndexController::_getAdminConnection |
( |
$ |
storageForm, |
|
|
$ |
adminForm |
|
) |
| [protected] |
Get a connection to the target Perforce Server as an administrator.
This method will not return a connection to a new local server; that is the responsibility of _createLocalServer().
- Parameters:
-
Zend_Form | $storageForm | the form with the target server port. |
Zend_Form | $adminForm | the form containing admin credentials. |
- Returns:
- P4_Connection_Interface an admin connection to the target server
{
if ($this->_adminP4) {
return $this->_adminP4;
}
$bootstrap = $this->getInvokeArg('bootstrap');
$port = $bootstrap->hasResource('perforce')
? $bootstrap->getResource('perforce')->getPort()
: $storageForm->getValue('port');
$adminP4 = P4_Connection::factory(
$port,
$adminForm->getValue('user'),
null,
$adminForm->getValue('password')
);
$adminP4->login();
return $adminP4;
}
Present rsh ports as 'Local Server: /path/to/server/root'.
Remote server ports are returned as-is.
- Parameters:
-
- Returns:
- string the friendly port
{
if ($this->_isRshServer($connection)) {
$info = $connection->getInfo();
return $info['serverRoot'];
}
return $connection->getPort();
}
Setup_IndexController::_isInitalSetup |
( |
| ) |
[protected] |
Check if setup is running for the first time.
We consider it the 'maiden voyage' if perforce is not yet configured.
- Returns:
- bool true if it is the first setup
{
return !$this->getInvokeArg('bootstrap')->hasResource('perforce');
}
Determines if given connection is to a local 'rsh' server.
- Parameters:
-
- Returns:
- bool true if connection uses rsh; false otherwise.
{
return strpos($connection->getPort(), 'rsh:') === 0;
}
Setup_IndexController::_p4ClientType |
( |
| ) |
|
Determine what Perforce client type is in use.
- Returns:
- string description of the client type
{
switch (get_class(P4_Connection::getDefaultConnection())) {
case "P4_Connection_CommandLine":
$type = 'Perforce command-line client, P4';
break;
case "P4_Connection_Extension":
$type = 'Perforce PHP extension, P4PHP';
break;
default:
$type = '(unknown client)';
break;
}
return $type;
}
Setup_IndexController::administratorAction |
( |
| ) |
|
Obtain server administrator information.
{
if (!$this->_isValidEnvironment()) {
$this->redirector->gotoSimple('requirements');
return;
}
$storageForm = new Setup_Form_Storage;
$storageForm->setCsrfProtection(false);
$session = $this->_getSession();
if (!is_array($session->storage) ||
!$storageForm->isValid($session->storage)) {
$this->redirector->gotoSimple('storage');
return;
}
$this->_cleanupSession();
$form = new Setup_Form_Administrator(
array(
'serverType' => $storageForm->getValue('serverType'),
'p4Port' => $session->storage['port']
)
);
$view = $this->view;
$perforce = $this->getInvokeArg('bootstrap')->getResource('perforce');
$view->port = $perforce ? $this->_getFriendlyPort($perforce) : $session->storage['port'];
$view->isRsh = $perforce ? $this->_isRshServer($perforce) : false;
$view->form = $form;
$view->headTitle()->set('Setup Administrator');
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
$session = $this->_getSession();
$session->administrator = $form->getValues();
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('storage');
return;
}
$this->redirector->gotoSimple('site');
return;
} elseif ($request->isPost()) {
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('storage');
return;
}
$count = count($form->getMessages());
$s = ($count == 1) ? '' : 's';
P4Cms_Notifications::add("$count field$s failed validation.", P4Cms_Notifications::SEVERITY_ERROR);
}
}
Setup_IndexController::createAction |
( |
| ) |
|
This action allows api's to make a single post to create a new site.
You should be able to succesfully add a site with the following post: storage[serverType]=new administrator[user]=<valid-user> administrator[email]=<valid-email> administrator[password]=<valid-password> administrator[passwordConfirm]=<valid-password> site[title]=<valid-title>
To use an existing perforce server replace the storage line with: storage[serverType]=existing storage[port]=perforce:1666
A json response will be returned with the following data: step = environment, storage, administrator, site or completed isValid = true or false errors = may contain a form key with an array of strings and/or an elements key which contains error arrays indexed by element id. value(s) can be ignored if isValid is true.
Note: the site[urls] field is only optional for the first site if any subsequent sites are added this field must be included.
{
$this->contextSwitch->initContext('json');
$request = $this->getRequest();
$session = $this->_getSession();
$session->administrator = $request->getPost('administrator');
$session->storage = $request->getPost('storage');
$site = (array) $request->getPost('site');
$request->setPost($site + array('administrator' => '', 'storage' => '', 'site' => ''));
$this->siteAction(true, $this->_isInitalSetup());
}
Setup_IndexController::indexAction |
( |
| ) |
|
Show setup splash page.
{
$this->_cleanupSession();
$request = $this->getRequest();
if ($request->getParam('start')) {
$this->_forward('requirements');
} else {
$startUrl = $request->getBaseUrl();
if ($this->_isRewriteWorking()) {
$startUrl .= '/setup/start/yes';
} else {
$startUrl .= '?start=yes';
}
$this->view->startUrl = $startUrl;
}
$this->view->headTitle()->set('Setup');
}
Setup_IndexController::init |
( |
| ) |
|
Use the setup layout and disable toolbar for all setup actions.
{
$this->_helper->layout->setLayout('setup-layout');
if (P4Cms_Cache::canCache('page')) {
P4Cms_Cache::getCache('page')->cancel();
}
$skipActions = array('rewrite', 'summary');
if (in_array($this->getRequest()->getActionName(), $skipActions)
|| $this->getInvokeArg('bootstrap')->isSetupNeeded()
) {
return;
}
$this->_helper->acl->check('site', 'add');
}
Setup_IndexController::requirementsAction |
( |
| ) |
|
Start setup process by checking requirements.
{
$this->_cleanupSession();
$this->view->headTitle()->set('Setup Requirements');
$this->view->isValidEnvironment = $this->_isValidEnvironment();
$this->view->isPhpValid = $this->_isPhpValid();
$this->view->isPhpVersionValid = $this->_isPhpVersionValid();
$this->view->phpVersion = PHP_VERSION;
$this->view->minPhpVersion = self::MIN_PHP_VERSION;
$this->view->isMagicQuotesOn = $this->_isMagicQuotesOn();
$this->view->isRewriteWorking = $this->_isRewriteWorking();
$this->view->isP4Valid = $this->_isP4Valid();
$this->view->p4Version = $this->_getP4Version();
$this->view->minP4Version = self::MIN_P4_VERSION;
$this->view->isP4Installed = $this->_isP4Installed();
$this->view->p4ClientType = $this->_p4ClientType();
$this->view->isDataPathValid = $this->_isDataPathValid();
$this->view->isDataPathPresent = $this->_isDataPathPresent();
$this->view->isDataPathWritable = $this->_isDataPathWritable();
$this->view->dataPath = DATA_PATH;
$this->view->isP4PHPInstalled = extension_loaded('perforce');
$this->view->isWinCacheInstalled = extension_loaded('wincache');
$this->view->isApcInstalled = extension_loaded('apc');
if (P4_Environment::isWindows() && isset($_SERVER['SERVER_SOFTWARE'])) {
$this->view->isWebServerIis = stripos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS") !== false;
}
$this->view->imageExtensions = array();
$this->view->imageExtensionsEnabled = array();
foreach (P4Cms_Image_Driver_Factory::getDriverClasses() as $driverClass) {
$extension = $driverClass::getRequiredExtension();
if (!$extension) {
continue;
}
$this->view->imageExtensions[] = $extension;
if (extension_loaded($extension)) {
$this->view->imageExtensionsEnabled[] = $extension;
}
}
try {
$defaultDriver = P4Cms_Image_Driver_Factory::create();
} catch (P4Cms_Image_Exception $e) {
$defaultDriver = null;
}
$commonTypes = array('jpeg', 'png', 'gif');
$this->view->defaultImageDriver = $defaultDriver;
$this->view->missingCommonImageTypes = $defaultDriver
? array_diff($commonTypes, array_filter($commonTypes, array($defaultDriver, 'isSupportedType')))
: array();
$webServerDetails = '';
if (function_exists("posix_geteuid")
&& function_exists("posix_getpwuid")
&& function_exists("posix_getgrgid")
) {
$userInfo = posix_getpwuid(posix_geteuid());
$userName = $userInfo['name'];
$groupInfo = posix_getgrgid($userInfo['gid']);
$groupName = $groupInfo['name'];
$webServerDetails = " (username \"$userName\", group \"$groupName\")";
}
$this->view->webServerDetails = $webServerDetails;
}
Setup_IndexController::rewriteAction |
( |
| ) |
|
Simple action exists only to be requested to test if rewrite is working.
Responds with a checksum of this file.
{
print(md5_file(__FILE__));
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
}
Setup_IndexController::siteAction |
( |
$ |
skipRedirect = false , |
|
|
$ |
optionalUrls = false |
|
) |
| |
Setup a site definition.
Both of the optional paramaters are intended for use by the 'create' action.
- Parameters:
-
bool | $skipRedirect | optional - if true skips trying to redirect backward for failed requirements and simply returns. |
bool | $optionalUrls | optional - if true the 'urls' field of the site form isn't required. |
{
if (!$this->_isValidEnvironment()) {
$this->view->step = 'environment';
$this->view->isValid = false;
$this->view->errors = array('form' => array('One or more requirements are not met.'));
$skipRedirect ?: $this->redirector->gotoSimple('requirements');
return;
}
$storageForm = new Setup_Form_Storage;
$storageForm->setCsrfProtection(false);
$session = $this->_getSession();
if (!$storageForm->isValid((array) $session->storage)) {
$this->view->step = 'storage';
$this->view->isValid = false;
$this->view->form = $storageForm;
$skipRedirect ?: $this->redirector->gotoSimple('storage');
return;
}
$options = array('serverType' => $session->storage['serverType']);
$adminForm = new Setup_Form_Administrator($options);
$adminForm->setCsrfProtection(false);
$adminForm->setP4Port($session->storage['port']);
$adminForm->setServerType($session->storage['serverType']);
if (!$adminForm->isValid((array) $session->administrator)) {
$this->view->step = 'administrator';
$this->view->isValid = false;
$this->view->form = $adminForm;
$skipRedirect ?: $this->redirector->gotoSimple('administrator');
return;
}
$view = $this->view;
$view->headTitle()->set('Setup Site');
$form = new Setup_Form_Site;
$view->form = $form;
$bootstrap = $this->getInvokeArg('bootstrap');
if ($bootstrap->hasResource('perforce')
|| $storageForm->getValue('serverType') !== $storageForm::SERVER_TYPE_NEW
) {
$form->setConnection(
$this->_getAdminConnection($storageForm, $adminForm)
);
}
if ($optionalUrls) {
$form->getElement('urls')->setRequired(false);
}
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('administrator');
return;
}
$site = $this->_createSite($form, $storageForm, $adminForm);
P4Cms_Cache::remove(P4Cms_Site::CACHE_KEY, 'global');
$session->site = $site;
$session->setupComplete = true;
$this->view->step = 'completed';
$this->view->isValid = true;
$skipRedirect ?: $this->redirector->gotoSimple('summary');
} elseif ($request->isPost()) {
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('administrator');
return;
}
$this->view->step = 'site';
$this->view->isValid = false;
$this->view->form = $form;
$count = count($form->getMessages());
$s = ($count == 1) ? '' : 's';
P4Cms_Notifications::add("$count field$s failed validation.", P4Cms_Notifications::SEVERITY_ERROR);
}
}
Setup_IndexController::storageAction |
( |
| ) |
|
Obtain Perforce server information.
{
if (!$this->_isValidEnvironment()) {
$this->redirector->gotoSimple('requirements');
return;
}
$form = new Setup_Form_Storage;
$this->view->form = $form;
$this->view->isP4dInstalled = $form->isP4dInstalled();
$this->view->isP4dValid = $form->isP4dValid();
$this->view->minP4Version = self::MIN_P4_VERSION;
$this->view->headTitle()->set('Setup Site Storage');
$request = $this->getRequest();
$perforce = $this->getInvokeArg('bootstrap')->getResource('perforce');
if ($perforce) {
$form->getElement('serverType')
->setAttrib('disabled', true)
->setValue($form::SERVER_TYPE_EXISTING);
$form->getElement('port')
->setAttrib('disabled', true)
->setValue($perforce->getPort())
->setDescription('You have already configured a Perforce Server.');
$request->setPost('serverType', $form::SERVER_TYPE_EXISTING)
->setPost('port', $perforce->getPort());
}
if ($request->isPost() && $form->isValid($request->getPost())) {
$session = $this->_getSession();
$session->storage = $form->getValues();
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('requirements');
return;
}
$this->redirector->gotoSimple('administrator');
return;
} elseif ($request->isPost()) {
if ($request->getParam('goback')) {
$this->redirector->gotoSimple('requirements');
return;
}
$count = count($form->getMessages());
$s = ($count == 1) ? '' : 's';
P4Cms_Notifications::add("$count field$s failed validation.", P4Cms_Notifications::SEVERITY_ERROR);
}
if ($form->getValue('serverType') == $form::SERVER_TYPE_NEW) {
$group = $form->getDisplayGroup('existingServer');
$group->setAttrib('class', $group->getAttrib('class') . ' disabled');
}
if ($perforce && $this->_isRshServer($perforce)) {
$form->getElement('port')
->setValue($this->_getFriendlyPort($perforce))
->setLabel('Local Server');
}
}
Setup_IndexController::summaryAction |
( |
| ) |
|
Summarize site setup - clear site from session.
{
if (!$this->_isValidEnvironment()) {
$this->redirector->gotoSimple('requirements');
return;
}
$session = $this->_getSession();
if (!isset($session->site)) {
$this->redirector->gotoSimple('site');
return;
}
$view = $this->view;
$perforce = $this->getInvokeArg('bootstrap')->getResource('perforce');
$view->port = $perforce ? $this->_getFriendlyPort($perforce) : $session->storage['port'];
$view->isRsh = $perforce ? $this->_isRshServer($perforce) : false;
$view->site = $session->site;
$view->storage = $session->storage;
$view->admin = $session->administrator;
$view->headTitle()->set('Setup Summary');
}
Member Data Documentation
Setup_IndexController::$_adminP4 = null [protected] |
Setup_IndexController::$_session = null [protected] |
Setup_IndexController::$contexts |
Initial value: array(
'requirements' => array('partial'),
'create' => array('json')
)
The documentation for this class was generated from the following file:
- application/setup/controllers/IndexController.php