00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 class InstallSettingsForm extends CFormModel
00041 {
00042 public $databaseHostname = 'localhost';
00043
00044 public $databaseAdminUsername;
00045
00046 public $databaseAdminPassword;
00047
00048 public $databaseName = 'zurmo';
00049
00050 public $databaseUsername = 'zurmo';
00051
00052 public $databasePassword;
00053
00054 public $databasePort = 3306;
00055
00056 public $superUserPassword;
00057
00058 public $memcacheHostname = '127.0.0.1';
00059
00060 public $memcachePortNumber = 11211;
00061
00062 protected $memcacheAvailable = true;
00063
00064 public $databaseType = 'mysql';
00065
00066 public $removeExistingData;
00067
00068 public $installDemoData = false;
00069
00070 public $hostInfo = '';
00071
00072 public $scriptUrl = '';
00073
00074 public $submitCrashToSentry = false;
00075
00076 public function rules()
00077 {
00078 return array(
00079 array('databaseHostname', 'required'),
00080 array('databaseName', 'required'),
00081 array('databaseUsername', 'required'),
00082 array('databasePassword', 'required'),
00083 array('databasePort', 'required'),
00084 array('superUserPassword', 'required'),
00085 array('hostInfo', 'required'),
00086 array('scriptUrl', 'required'),
00087 array('databaseHostname', 'type', 'type' => 'string'),
00088 array('databaseAdminUsername', 'type', 'type' => 'string'),
00089 array('databaseAdminPassword', 'type', 'type' => 'string'),
00090 array('databaseName', 'type', 'type' => 'string'),
00091 array('databaseUsername', 'type', 'type' => 'string'),
00092 array('databasePassword', 'type', 'type' => 'string'),
00093 array('superUserPassword', 'type', 'type' => 'string'),
00094 array('memcacheHostname', 'type', 'type' => 'string'),
00095 array('memcachePortNumber', 'type', 'type' => 'integer'),
00096 array('memcachePortNumber', 'numerical', 'min' => 1024),
00097 array('removeExistingData', 'boolean'),
00098 array('installDemoData', 'boolean'),
00099 array('hostInfo', 'type', 'type' => 'string'),
00100 array('scriptUrl', 'type', 'type' => 'string'),
00101 array('submitCrashToSentry', 'boolean'),
00102 );
00103 }
00104
00105 public function setMemcacheIsNotAvailable()
00106 {
00107 $this->memcacheAvailable = false;
00108 $this->memcacheHostname = null;
00109 $this->memcachePortNumber = null;
00110 }
00111
00112 public function getIsMemcacheAvailable()
00113 {
00114 return $this->memcacheAvailable;
00115 }
00116
00121 public function afterValidate()
00122 {
00123 parent::afterValidate();
00124 if (count($this->getErrors()) == 0)
00125 {
00126
00127 if ($this->memcacheHostname != null)
00128 {
00129 if ($this->memcachePortNumber == null)
00130 {
00131 $this->addError('memcachePortNumber', Zurmo::t('InstallModule', 'Since you specified a memcache ' .
00132 'hostname, you must specify a port.'));
00133 return;
00134 }
00135 $memcacheResult = InstallUtil::checkMemcacheConnection($this->memcacheHostname,
00136 (int)$this->memcachePortNumber);
00137 if ($memcacheResult !== true)
00138 {
00139 $this->addError('memcacheHostname', Zurmo::t('Core', 'Error code:') . " " .
00140 $memcacheResult[0] . '<br/>Message(Memcached): ' . $memcacheResult[1]);
00141 return;
00142 }
00143 }
00144
00145 if (!$this->hostInfo)
00146 {
00147 $this->addError('hostInfo', Zurmo::t('InstallModule', 'Please enter server IP or URL.'));
00148 return;
00149 }
00150 else
00151 {
00152 if ((strpos($this->hostInfo, 'http://') === false) && (strpos($this->hostInfo, 'https://') === false))
00153 {
00154 $this->addError('hostInfo', Zurmo::t('InstallModule', 'Host Info must start with "http://" or "https://".'));
00155 return;
00156 }
00157 }
00158
00159 if ($this->databaseAdminUsername != null)
00160 {
00161 if ($this->databaseAdminPassword == null)
00162 {
00163 $this->addError('databaseAdminPassword', Zurmo::t('InstallModule', 'Since you specified a database ' .
00164 'admin username, you must enter a password'));
00165 return;
00166 }
00167 $connectionResult = DatabaseCompatibilityUtil::checkDatabaseConnection($this->databaseType,
00168 $this->databaseHostname,
00169 $this->databaseAdminUsername,
00170 $this->databaseAdminPassword,
00171 (int)$this->databasePort);
00172 if ($connectionResult !== true)
00173 {
00174 $this->addError('databaseAdminUsername', Zurmo::t('Core', 'Error code:') . " " .
00175 $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
00176 return;
00177 }
00178 $userExistsResult = DatabaseCompatibilityUtil::checkDatabaseUserExists($this->databaseType,
00179 $this->databaseHostname,
00180 $this->databaseAdminUsername,
00181 $this->databaseAdminPassword,
00182 (int)$this->databasePort,
00183 $this->databaseUsername);
00184 if ($userExistsResult === true)
00185 {
00186 $this->addError('databaseUsername', Zurmo::t('InstallModule', 'You have specified an existing user. ' .
00187 'If you would like to use this user, then do not specify the database admin username and ' .
00188 'password. Otherwise pick a database username that does not exist.'));
00189 return;
00190 }
00191 $databaseExistsResult = DatabaseCompatibilityUtil::checkDatabaseExists($this->databaseType,
00192 $this->databaseHostname,
00193 $this->databaseAdminUsername,
00194 $this->databaseAdminPassword,
00195 (int)$this->databasePort,
00196 $this->databaseName);
00197 if ($databaseExistsResult === true)
00198 {
00199 $this->addError('databaseName', Zurmo::t('InstallModule', 'You have specified an existing database. ' .
00200 'If you would like to use this database, then do not specify the database admin username and ' .
00201 'password. Otherwise pick a database name that does not exist.'));
00202 return;
00203 }
00204 $createDatabaseResult = DatabaseCompatibilityUtil::createDatabase($this->databaseType,
00205 $this->databaseHostname,
00206 $this->databaseAdminUsername,
00207 $this->databaseAdminPassword,
00208 (int)$this->databasePort,
00209 $this->databaseName);
00210 if ($createDatabaseResult === false)
00211 {
00212 $this->addError('databaseName', Zurmo::t('InstallModule', 'There was a problem creating the database ' .
00213 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
00214 return;
00215 }
00216 $createUserResult = DatabaseCompatibilityUtil::createDatabaseUser($this->databaseType,
00217 $this->databaseHostname,
00218 $this->databaseAdminUsername,
00219 $this->databaseAdminPassword,
00220 (int)$this->databasePort,
00221 $this->databaseName,
00222 $this->databaseUsername,
00223 $this->databasePassword);
00224 if ($createUserResult === false)
00225 {
00226 $this->addError('databaseUsername', Zurmo::t('InstallModule', 'There was a problem creating the user ' .
00227 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
00228 return;
00229 }
00230 }
00231 else
00232 {
00233 $connectionResult = DatabaseCompatibilityUtil::checkDatabaseConnection($this->databaseType,
00234 $this->databaseHostname,
00235 $this->databaseUsername,
00236 $this->databasePassword,
00237 (int)$this->databasePort);
00238 if ($connectionResult !== true)
00239 {
00240 $this->addError('databaseUsername', Zurmo::t('Core', 'Error code:') . " " .
00241 $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
00242 return;
00243 }
00244 $databaseExistsResult = DatabaseCompatibilityUtil::checkDatabaseExists($this->databaseType,
00245 $this->databaseHostname,
00246 $this->databaseUsername,
00247 $this->databasePassword,
00248 (int)$this->databasePort,
00249 $this->databaseName);
00250 if ($databaseExistsResult !== true)
00251 {
00252 $this->addError('databaseName', Zurmo::t('InstallModule', 'The database name specified does not ' .
00253 'exist or the user specified does not have access.') . '<br/>' .
00254 Zurmo::t('Core', 'Error code:') . " " . $databaseExistsResult[0] .
00255 '<br/>Message: ' . $databaseExistsResult[1]);
00256 return;
00257 }
00258 else
00259 {
00260 if ($this->removeExistingData == false)
00261 {
00262 $this->addError('removeExistingData', Zurmo::t('InstallModule', 'Since you specified an existing database ' .
00263 'you must check this box in order to proceed. THIS WILL REMOVE ALL EXISTING DATA.'));
00264 return;
00265 }
00266 }
00267 }
00268 }
00269 }
00270 }
00271 ?>