Commit 97cb0cd121663af35556a1a6652228728509a011

Authored by megan_w
1 parent 72c27c3c

KTC-395

"Unable to compare content versions for a txt doc or an Open Office document"
Fixed. Changed the way it checks if open office is running.

Committed By: Megan Watson
Reviewed By: Conrad Vermeulen

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8188 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 86 additions and 27 deletions
bin/checkopenoffice.php
... ... @@ -39,46 +39,105 @@
39 39 chdir(realpath(dirname(__FILE__)));
40 40 require_once('../config/dmsDefaults.php');
41 41  
42   -// Check if open office is running
  42 +/*
  43 +Script checks if open office is running, if it isn't then it attempts to start it.
  44 +
  45 +Windows Vista always returns false if we try and check the host and port
  46 +so for windows we use the win32 service status checks.
  47 +
  48 +*/
  49 +
  50 +// Check if the calling function requires a return value
  51 +$sGiveOutput = (isset($argv[1]) && $argv[1] == 'output') ? true : false;
  52 +
  53 +// First we check the host:port to see if open office is running
43 54 $sCheckOO = SearchHelper::checkOpenOfficeAvailablity();
44 55  
45   -// If it is running - exit, we don't need to do anything otherwise start it
46   -if(!empty($sCheckOO)){
  56 +if(empty($sCheckOO)){
  57 + // If the check returns empty then it is available on that port so we exit
  58 + if($sGiveOutput){
  59 + echo 1;
  60 + }
  61 + exit;
  62 +}
  63 +
  64 +// Open office appears not to be running.
  65 +
  66 +if(OS_WINDOWS){
  67 + // If this is vista, it might be being blocked, so we query the service
  68 + $OOService = 'ktopenoffice';
  69 + $result = win32_query_service_status($OOService);
  70 +
  71 + if(is_array($result)){
  72 + $iProcessId = $result['ProcessId'];
  73 + if(!empty($iProcessId) && $iProcessId != 0){
  74 + // If there is a process id (PID) then open office is running so we exit
  75 + if($sGiveOutput){
  76 + echo 1;
  77 + }
  78 + exit;
  79 + }
  80 + }
47 81  
  82 + // Service is not running - log it and attempt to start
48 83 $default->log->debug('Check Open Office Task: Open office service is not running... trying to start it.');
49 84  
50   - if(OS_WINDOWS){
  85 + // Use the win32 service start
  86 + $result2 = win32_start_service($OOService);
51 87  
52   - // Check the path first
53   - $sPath = realpath('../../bin/winserv.exe');
  88 + if($result2 == 0){
  89 + // Service started successfully
  90 + $default->log->debug('Check Open Office Task: Open office service started.');
  91 + if($sGiveOutput){
  92 + echo 1;
  93 + }
  94 + exit;
  95 + }
  96 +
  97 + $default->log->debug('Check Open Office Task: Open office service could not be started. Error code '.$result2);
54 98  
55   - if(file_exists($sPath)){
56   - $sCmd = "\"$sPath\" start ktopenoffice";
57   - KTUtil::pexec($sCmd);
58   - exit;
  99 +
  100 + // Attempt using the dmsctl batch script
  101 + $sPath = realpath('../../bin/dmsctl.bat');
  102 + if(file_exists($sPath)){
  103 + $sCmd = "\"$sPath\" start";
  104 + $res = KTUtil::pexec($sCmd);
  105 +
  106 + $default->log->debug('Check Open Office Task: Attempted start using dmsctl.bat.');
  107 + if($sGiveOutput){
  108 + echo 2;
59 109 }
60   - // If that doesn't work, check for the all start
61   - $sPath = realpath('../../bin/dmsctl.bat');
62   - if(file_exists($sPath)){
63   - $sCmd = "\"$sPath\" start";
64   - KTUtil::pexec($sCmd);
65   - exit;
  110 + exit;
  111 + }else{
  112 + $default->log->debug('Check Open Office Task: Can\'t find dmsctl.bat, this may be a source install.');
  113 + if($sGiveOutput){
  114 + echo 0;
  115 + }
  116 + exit;
  117 + }
  118 +}else{
  119 + // If the OS is Unix or Linux
  120 + $sPath = realpath('../../dmsctl.sh');
  121 + if(file_exists($sPath)){
  122 + $sCmd = "\"$sPath\" start";
  123 + KTUtil::pexec($sCmd);
  124 +
  125 + $default->log->debug('Check Open Office Task: Attempted start using dmsctl.sh.');
  126 + if($sGiveOutput){
  127 + echo 2;
66 128 }
67   - // Might be a source install ... ???
68   - $default->log->debug('Check Open Office Task: Can\'t start Open office, this may be a source install.');
69 129 exit;
70 130 }else{
71   - $sPath = realpath('../../dmsctl.sh');
72   - if(file_exists($sPath)){
73   - $sCmd = "\"$sPath\" start";
74   - KTUtil::pexec($sCmd);
75   - exit;
  131 + $default->log->debug('Check Open Office Task: Can\'t find dmsctl.sh, this may be a source install.');
  132 + if($sGiveOutput){
  133 + echo 0;
76 134 }
77   - // might be a source install
78   - $default->log->debug('Check Open Office Task: Can\'t start Open office, this may be a source install.');
79 135 exit;
80   - }
  136 + }
  137 +}
  138 +$default->log->debug('Check Open Office Task: Can\'t start Open office, this may be a source install.');
  139 +if($sGiveOutput){
  140 + echo 0;
81 141 }
82   -
83 142 exit;
84 143 ?>
85 144 \ No newline at end of file
... ...