Commit 9873970c18c8d940d574e68c435fc76785468f84

Authored by jarrett
1 parent 9411acf6

Story Id: 964068 Updated Templating

Committed by: Jarrett Jordaan

Reviewed by: Paul Barrett
setup/wizard/installUtil.php
... ... @@ -373,7 +373,6 @@ class InstallUtil {
373 373 }
374 374  
375 375 return 'java';
376   -// return array('response'=>$response, 'java'=>'java');
377 376 }
378 377  
379 378 function tryJava2() {
... ... @@ -383,7 +382,6 @@ class InstallUtil {
383 382 }
384 383  
385 384 return 'java';
386   -// return array('response'=>$response, 'java'=>'java');
387 385 }
388 386  
389 387 function tryJava3() {
... ... @@ -396,7 +394,6 @@ class InstallUtil {
396 394 $match = preg_match('/bin/', $r);
397 395 if($match) {
398 396 return preg_replace('/java:/', '', $r);
399   -// return array('response'=>$response, 'java'=>preg_replace('/java:/', '', $r));
400 397 }
401 398 }
402 399 }
... ... @@ -422,6 +419,26 @@ class InstallUtil {
422 419 }
423 420  
424 421 /**
  422 + * Check if user entered location of PHP
  423 + *
  424 + * @author KnowledgeTree Team
  425 + * @param none
  426 + * @access private
  427 + * @return mixed
  428 + */
  429 + public function phpSpecified() {
  430 + if(isset($_POST['php'])) {
  431 + if($_POST['php'] != '') {
  432 + return $_POST['php'];
  433 + } else {
  434 + return false;
  435 + }
  436 + } else {
  437 + return false;
  438 + }
  439 + }
  440 +
  441 + /**
425 442 * Determine the location of JAVA_HOME
426 443 *
427 444 * @author KnowledgeTree Team
... ... @@ -441,6 +458,30 @@ class InstallUtil {
441 458 return $response;
442 459 }
443 460  
  461 + /**
  462 + * Determine the location of PHP
  463 + *
  464 + * @author KnowledgeTree Team
  465 + * @param none
  466 + * @access private
  467 + * @return mixed
  468 + */
  469 + function getPhp() {
  470 + $cmd = "whereis php";
  471 + $response = $this->pexec($cmd);
  472 + if(is_array($response['out'])) {
  473 + $broke = explode(' ', $response['out'][0]);
  474 + foreach ($broke as $r) {
  475 + $match = preg_match('/bin/', $r);
  476 + if($match) {
  477 + return preg_replace('/php:/', '', $r);
  478 + }
  479 + }
  480 + }
  481 +
  482 + return '';
  483 + }
  484 +
444 485 /**
445 486 * Portably execute a command on any of the supported platforms.
446 487 *
... ...
setup/wizard/lib/services/unixLucene.php
... ... @@ -147,7 +147,12 @@ class unixLucene extends unixService {
147 147 }
148 148  
149 149 public function install() {
150   - $this->start();
  150 + $status = $this->status();
  151 + if($status == '') {
  152 + return $this->start();
  153 + } else {
  154 + return $status;
  155 + }
151 156 }
152 157  
153 158 public function status() {
... ... @@ -162,11 +167,11 @@ class unixLucene extends unixService {
162 167 }
163 168 }
164 169 } else {
165   - return 'STOPPED';
  170 + return '';
166 171 }
167 172 }
168 173  
169   - return 'STOPPED';
  174 + return '';
170 175 }
171 176  
172 177 public function uninstall() {
... ...
setup/wizard/lib/services/unixScheduler.php
... ... @@ -108,7 +108,12 @@ class unixScheduler extends unixService {
108 108 }
109 109  
110 110 function install() {
111   - $this->start();
  111 + $status = $this->status();
  112 + if($status == '') {
  113 + return $this->start();
  114 + } else {
  115 + return $status;
  116 + }
112 117 }
113 118  
114 119 function uninstall() {
... ... @@ -133,7 +138,7 @@ class unixScheduler extends unixService {
133 138 }
134 139 }
135 140 } else {
136   - return 'STOPPED';
  141 + return '';
137 142 }
138 143 }
139 144  
... ...
setup/wizard/steps/complete.php
... ... @@ -237,7 +237,7 @@ class complete extends Step {
237 237 $className = OS.$serviceName;
238 238 $service = new $className();
239 239 $service->load();
240   - if($service->status() == 'RUNNING') {
  240 + if($service->status() == 'RUNNING' || $service->status() == 'STARTED') {
241 241 $this->temp_variables[$serviceName."Status"] = 'tick';
242 242 } else {
243 243 $this->temp_variables[$serviceName."Status"] = 'cross_orange';
... ...
setup/wizard/steps/configuration.php
... ... @@ -136,9 +136,15 @@ class configuration extends Step
136 136 $this->setDetails();
137 137 return 'previous';
138 138 } else if($this->confirm()) {
139   - return 'next';
  139 + if($this->doRun()) {
  140 + return 'next';
  141 + }
  142 + return 'error';
140 143 } else if($this->edit()) {
141 144 $this->setDetails();
  145 + if($this->doRun()) {
  146 +
  147 + }
142 148 return 'landing';
143 149 }
144 150  
... ... @@ -345,6 +351,7 @@ class configuration extends Step
345 351  
346 352 if($class['class'] != 'tick') {
347 353 $this->temp_variables['paths_perms'] = $class['class'];
  354 + $this->done = false;
348 355 }
349 356 $dirs[$key] = array_merge($dirs[$key], $class);
350 357 }
... ...
setup/wizard/steps/services.php
... ... @@ -80,6 +80,24 @@ class services extends Step
80 80 private $javaCheck = 'cross';
81 81  
82 82 /**
  83 + * Flag if services are already Installed
  84 + *
  85 + * @author KnowledgeTree Team
  86 + * @access private
  87 + * @var mixed
  88 + */
  89 + private $alreadyInstalled = false;
  90 +
  91 + /**
  92 + * PHP Installed
  93 + *
  94 + * @author KnowledgeTree Team
  95 + * @access private
  96 + * @var mixed
  97 + */
  98 + private $phpCheck = 'cross_orange';
  99 +
  100 + /**
83 101 * Java Bridge Installed
84 102 *
85 103 * @author KnowledgeTree Team
... ... @@ -104,7 +122,7 @@ class services extends Step
104 122 * @access public
105 123 * @var boolean
106 124 */
107   - protected $storeInSession = false;
  125 + protected $storeInSession = true;
108 126  
109 127 /**
110 128 * List of variables to be loaded to template
... ... @@ -140,16 +158,16 @@ class services extends Step
140 158 * @access public
141 159 * @var mixed
142 160 */
143   - private $javaExeError = false;
  161 + private $javaExeError = '';
144 162  
145 163 /**
146   - * Holds path error, if java is specified
  164 + * Holds path error, if php is specified
147 165 *
148 166 * @author KnowledgeTree Team
149 167 * @access public
150 168 * @var mixed
151 169 */
152   - private $phpExeError = false;
  170 + private $phpExeError = '';
153 171 /**
154 172 * Constructs services object
155 173 *
... ... @@ -213,6 +231,7 @@ class services extends Step
213 231 if($this->java != '') { // Java JRE Found
214 232 $this->javaCheck = 'tick';
215 233 $this->javaInstalled();
  234 + $this->temp_variables['java']['location'] = $this->java;
216 235 }
217 236 }
218 237  
... ... @@ -225,24 +244,60 @@ class services extends Step
225 244 * @return boolean
226 245 */
227 246 private function doRun() {
228   - $this->setPhpDir(); // Get php, if it exists
229   - $this->java = $this->util->getJava(); // Get java, if it exists
230   - $this->javaChecks(); // Run Pre Checks
231   - $errors = $this->getErrors(); // Get errors
232   - if(empty($errors)) { // Install Service if there is no errors
233   - $this->installService();
234   - } else { // Services not installed
235   - foreach ($this->getServices() as $serviceName) {
236   - $this->temp_variables['services'][] = array('class'=>'cross_orange', 'msg'=>$serviceName." Could not be added as a Service");
  247 + if($this->alreadyInstalled()) {
  248 + $this->alreadyInstalled = true;
  249 + $this->serviceCheck = 'tick';
  250 + } else {
  251 + $this->php = $this->util->getPhp(); // Get java, if it exists
  252 + $this->java = $this->util->getJava(); // Get java, if it exists
  253 + $passedPhp = $this->phpChecks(); // Run Java Pre Checks
  254 + $passedJava = $this->javaChecks(); // Run Java Pre Checks
  255 + $errors = $this->getErrors(); // Get errors
  256 + if(empty($errors) && $passedJava && $passedPhp) { // Install Service if there is no errors
  257 + $this->installServices();
  258 + } elseif ($passedPhp) { // Install Scheduler
  259 + $this->installService('Scheduler');
  260 + } elseif ($passedJava) { // Install Lucene
  261 + $this->installService('Lucene');
  262 + } else { // All Services not installed
237 263 }
238   - $this->serviceCheck = 'cross_orange';
239   - }
  264 + }
  265 + $this->checkServiceStatus();
240 266 $this->storeSilent(); // Store info needed for silent mode
241 267 if(!empty($errors))
242 268 return false;
243 269 return true;
244 270 }
245 271  
  272 + function checkServiceStatus() {
  273 + $serverDetails = $this->getServices();
  274 + foreach ($serverDetails as $serviceName) {
  275 + $className = OS.$serviceName;
  276 + $service = new $className();
  277 + $status = $this->serviceStatus($service);
  278 + if($status != 'STARTED') {
  279 + $this->temp_variables['services'][] = array('class'=>'cross_orange', 'msg'=>$service->getName()." Could not be added as a Service");
  280 + $this->serviceCheck = 'cross_orange';
  281 + } else {
  282 + $this->temp_variables['services'][] = array('class'=>'tick', 'msg'=>$service->getName()." has been added as a Service");
  283 + }
  284 + }
  285 + }
  286 +
  287 + function alreadyInstalled() {
  288 + $installed = true;
  289 + $serverDetails = $this->getServices();
  290 + foreach ($serverDetails as $serviceName) {
  291 + $className = OS.$serviceName;
  292 + $service = new $className();
  293 + $status = $this->serviceStatus($service);
  294 + if($status != 'STARTED') {
  295 + return false;
  296 + }
  297 + }
  298 + return true;
  299 + }
  300 +
246 301 /**
247 302 * Do some basic checks to help the user overcome java problems
248 303 *
... ... @@ -260,10 +315,36 @@ class services extends Step
260 315 $this->disableExtension = true; // Disable the use of the php bridge extension
261 316 return $this->detSettings(); // AutoDetect java settings
262 317 } else {
263   - return $this->useBridge(); // Use Bridge to get java settings
  318 + $auto = $this->useBridge(); // Use Bridge to get java settings
  319 + if($auto) {
  320 + return $auto;
  321 + } else {
  322 + $this->specifyJava(); // Ask for settings
  323 + }
  324 + return $auto;
264 325 }
265 326 }
266   -
  327 +
  328 + private function specifyJava() {
  329 + $this->javaExeError = true;
  330 + }
  331 +
  332 + private function specifyPhp() {
  333 + $this->phpExeError = true;
  334 + }
  335 +
  336 + private function phpChecks() {
  337 + // TODO: Better detection
  338 + return true;
  339 + $this->setPhp();
  340 + if($this->util->phpSpecified()) {
  341 + return $this->detPhpSettings();
  342 + } else {
  343 + $this->specifyPhp();// Ask for settings
  344 + return false;
  345 + }
  346 + }
  347 +
267 348 /**
268 349 * Attempts to use user input and configure java settings
269 350 *
... ... @@ -289,18 +370,41 @@ class services extends Step
289 370 $this->javaVersionCorrect();
290 371 $this->javaInstalled();
291 372 $this->javaCheck = 'tick';
  373 +
292 374 return true;
293 375 }
294 376 } else {
295 377 $this->javaVersionWarning();
296 378 $this->javaCheck = 'cross_orange';
297   - $this->javaExeError = "Incorrect path specified";
  379 + $this->javaExeError = "Java : Incorrect path specified";
298 380 $this->error[] = "Requires Java 1.5+ to be installed";
299 381 return false;
300 382 }
301 383 }
302 384 }
303 385  
  386 + function detPhpSettings() {
  387 + // TODO: Better php handling
  388 + return true;
  389 + $phpExecutable = $this->util->phpSpecified();// Retrieve java bin
  390 + $cmd = "$phpExecutable -version > output/outPHP 2>&1 echo $!";
  391 + $response = $this->util->pexec($cmd);
  392 + if(file_exists(OUTPUT_DIR.'outPHP')) {
  393 + $tmp = file_get_contents(OUTPUT_DIR.'outPHP');
  394 + preg_match('/PHP/',$tmp, $matches);
  395 + if($matches) {
  396 + $this->phpCheck = 'tick';
  397 +
  398 + return true;
  399 + } else {
  400 + $this->phpCheck = 'cross_orange';
  401 + $this->phpExeError = "PHP : Incorrect path specified";
  402 + $this->error[] = "PHP executable required";
  403 +
  404 + return false;
  405 + }
  406 + }
  407 + }
304 408 /**
305 409 * Attempts to use bridge and configure java settings
306 410 *
... ... @@ -329,6 +433,7 @@ class services extends Step
329 433 return true;
330 434 }
331 435 } else {
  436 + $this->javaCheck = 'cross_orange';
332 437 $this->javaVersionWarning();
333 438 $this->zendBridgeWarning();
334 439 $this->warnings[] = "Zend Java Bridge Not Functional";
... ... @@ -379,27 +484,36 @@ class services extends Step
379 484 *
380 485 * @author KnowledgeTree Team
381 486 * @param none
382   - * @access public
  487 + * @access private
383 488 * @return boolean
384 489 */
385   - public function installService() {
  490 + private function installServices() {
386 491 foreach ($this->getServices() as $serviceName) {
387   - $className = OS.$serviceName;
388   - $service = new $className();
389   - $status = $this->serviceHelper($service);
390   - if ($status) {
391   - $this->temp_variables['services'][] = array('class'=>'tick', 'msg'=>$service->getName()." has been added as a Service");
392   - } else {
393   - $this->temp_variables['services'][] = array('class'=>'cross_orange', 'msg'=>$service->getName()." Could not be added as a Service");
394   - $this->serviceCheck = 'cross_orange';
395   - }
  492 + $this->installService($serviceName);
396 493 }
397 494  
398 495 return true;
399 496 }
400 497  
  498 + /**
  499 + * Installs services helper
  500 + *
  501 + * @author KnowledgeTree Team
  502 + * @param none
  503 + * @access private
  504 + * @return boolean
  505 + */
  506 + private function installService($serviceName) {
  507 + $className = OS.$serviceName;
  508 + $service = new $className();
  509 + $status = $this->serviceHelper($service);
  510 + if (!$status) {
  511 + $this->serviceCheck = 'cross_orange';
  512 + }
  513 + }
  514 +
401 515 /**
402   - * Executes services
  516 + * Installs services
403 517 *
404 518 * @author KnowledgeTree Team
405 519 * @param object
... ... @@ -414,6 +528,20 @@ class services extends Step
414 528 }
415 529  
416 530 /**
  531 + * Returns service status
  532 + *
  533 + * @author KnowledgeTree Team
  534 + * @param object
  535 + * @access private
  536 + * @return string
  537 + */
  538 + private function serviceStatus($service) {
  539 + $service->load(); // Load Defaults
  540 + $statusCheck = OS."ServiceInstalled";
  541 + return $this->$statusCheck($service);
  542 + }
  543 +
  544 + /**
417 545 * Check if windows service installed
418 546 *
419 547 * @author KnowledgeTree Team
... ... @@ -424,7 +552,6 @@ class services extends Step
424 552 public function windowsServiceInstalled($service) {
425 553 $status = $service->status(); // Check if service has been installed
426 554 if($status == '') { // Check service status
427   - $this->error[] = $service->getName()." Could not be added as a Service";
428 555 return false;
429 556 }
430 557 return true;
... ... @@ -441,7 +568,6 @@ class services extends Step
441 568 public function unixServiceInstalled($service) {
442 569 $status = $service->status(); // Check if service has been installed
443 570 if($status != 'STARTED') { // Check service status
444   - $this->error[] = $service->getName()." Could not be added as a Service";
445 571 return false;
446 572 }
447 573 return true;
... ... @@ -460,9 +586,7 @@ class services extends Step
460 586 $className = OS.$serviceName;
461 587 $service = new $className();
462 588 $status = $this->serviceStart($service);
463   -
464 589 }
465   -
466 590 return true;
467 591 }
468 592  
... ... @@ -630,40 +754,28 @@ class services extends Step
630 754 * @return void
631 755 */
632 756 private function storeSilent() {
633   - $this->temp_variables['javaExeError'] = $this->javaExeError;
634   - $this->temp_variables['phpExeError'] = $this->phpExeError;
635   - $this->temp_variables['javaCheck'] = $this->javaCheck;
636   - $this->temp_variables['javaExtCheck'] = $this->javaExtCheck;
637   - $this->temp_variables['serviceCheck'] = $this->serviceCheck;
638   - $this->temp_variables['disableExtension'] = $this->disableExtension;
  757 + $this->temp_variables['alreadyInstalled'] = $this->alreadyInstalled;
  758 + $this->temp_variables['javaExeError'] = $this->javaExeError;
  759 + $this->temp_variables['javaCheck'] = $this->javaCheck;
  760 + $this->temp_variables['javaExtCheck'] = $this->javaExtCheck;
  761 + $this->temp_variables['phpCheck'] = 'tick';//$this->phpCheck;
  762 + $this->temp_variables['phpExeError'] = '';//$this->phpExeError;
  763 + $this->temp_variables['serviceCheck'] = $this->serviceCheck;
  764 + $this->temp_variables['disableExtension'] = $this->disableExtension;
639 765 }
640   -
641   - private function setPhpDir($phpdir = '') {
642   - if(PHP_DIR != '') {
  766 +
  767 + private function setPhp() {
  768 + if($this->php != '') { // PHP Found
  769 + $this->phpCheck = 'tick';
  770 + } elseif (PHP_DIR != '') { // Use System Defined Settings
643 771 $this->php = PHP_DIR;
644   - }
645   - if($phpdir == '') {
646   - $cmd = "whereis php";
647   - $response = $this->util->pexec($cmd);
648   - if(is_array($response['out'])) {
649   - $broke = explode(' ', $response['out'][0]);
650   - foreach ($broke as $r) {
651   - $match = preg_match('/bin/', $r);
652   - if($match) {
653   - $this->php = preg_replace('/php:/', '', $r);
654   - return true;
655   - }
656   - }
657   - }
658 772 } else {
659   - $this->php = $phpdir;
660   - }
661   - if($this->php == '') {
662   - $this->phpExeError = "Incorrect path specified";
  773 +
663 774 }
664   - }
  775 + $this->temp_variables['php']['location'] = $this->php;
  776 + }
665 777  
666   - private function getPhpDir() {
  778 + public function getPhpDir() {
667 779 return $this->php;
668 780 }
669 781 }
... ...
setup/wizard/templates/services.tpl
... ... @@ -11,20 +11,29 @@ if($errors || $warnings){
11 11 . 'Click Here for help on overcoming service issues</a></div><br/>';
12 12 }
13 13 ?>
14   -<?php if($javaExtCheck != 'tick') { ?>
  14 +<?php if(!$alreadyInstalled) { ?>
  15 +<?php if($javaExeError != '') { ?>
15 16 Specify the location of your Java executable
16 17 <br />
17   -<input name='java' id='port' size='25' value=''/>
  18 +<input name='java' id='port' size='25' value='<?php echo $java['location']; ?>'/>
18 19 &nbsp;&nbsp;&nbsp;
19   -<?php if($phpExtCheck != 'tick') { ?>
  20 +<?php if($javaExeError != true) { ?><span class="error"><?php echo $javaExeError; ?></span><?php } ?>
  21 +<?php } ?>
  22 +<?php if($phpExeError != '') { ?>
  23 +<br />
20 24 Specify the location of your PHP executable
21 25 <br />
22   -<input name='php' id='port' size='25' value=''/>
  26 +<?php if($php['location'] == '') { ?>
  27 + <input name='php' id='port' size='25' value='<?php echo $php['location']; ?>'/>
  28 +<?php } else {?>
  29 + <input type="hidden" name='php' id='port' size='25' value='<?php echo $php['location']; ?>'/>
23 30 <?php } ?>
24   -<input type="submit" name="Refresh" value="Submit"/>
  31 +&nbsp;&nbsp;&nbsp;
  32 +<?php if($phpExeError != true) { ?><span class="error"><?php echo $phpExeError; ?></span><?php } ?>
  33 +<?php } ?>
  34 +<?php if($javaExeError != '' || $phpExeError != '') { ?>
25 35 <br />
26   -<?php if($javaExeError) { ?><span class="error"><?php echo $javaExeError; ?></span><?php } ?>
27   -
  36 +<input type="submit" name="Refresh" value="Submit"/>
28 37 <?php } ?>
29 38 <h3><?php echo "<span class='{$javaCheck}'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>"; ?>Java Check</h3>
30 39 <?php if($silent) { ?>
... ... @@ -55,6 +64,11 @@ A PHP Java Bridge is required for KnowledgeTree to perform at an optimal level.
55 64 </div>
56 65 <?php } ?>
57 66 <?php } ?>
  67 +<?php } else { ?>
  68 +<p class="description">
  69 +All services are already installed.
  70 +</p>
  71 +<?php } ?>
58 72 <h3><?php echo "<span class='{$serviceCheck}'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>"; ?>Services Check</h3>
59 73 <?php if($silent) { ?>
60 74 <div id="options" class="onclick" onclick="javascript:{w.toggleClass('service_details');}">Show Details</div>
... ...