init.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. $phpcli = $argv[1];
  3. $pmsRoot = $argv[2];
  4. $basePath = dirname(__FILE__, 3);
  5. chdir($basePath);
  6. include './framework/router.class.php';
  7. include './framework/control.class.php';
  8. include './framework/model.class.php';
  9. include './framework/helper.class.php';
  10. try
  11. {
  12. $app = router::createApp('pms', $basePath, 'router');
  13. }
  14. catch (Exception $exception)
  15. {
  16. die("Connect database fail. Please open mysql service.\n");
  17. }
  18. $suffix = stripos(PHP_OS, 'WIN') !== false ? '.bat' : '.sh';
  19. $requestType = $app->config->requestType;
  20. $binPath = $basePath . '/bin';
  21. $crond = "# system cron.\n";
  22. $crond .= "#min \t hour \t day \t month \t week \t command.\n";
  23. /* Remove old cron. */
  24. foreach(glob("$binPath/*{$suffix}") as $file)
  25. {
  26. $fileName = basename($file);
  27. if($fileName == "init{$suffix}") continue;
  28. unlink($file);
  29. }
  30. $crons = $app->dbh->query('SELECT * FROM ' . TABLE_CRON . " WHERE `type`='zentao' AND `status`='normal' AND `buildin`='1'")->fetchAll();
  31. foreach($crons as $cron)
  32. {
  33. parse_str($cron->command, $params);
  34. if(empty($params)) continue;
  35. $command = '';
  36. if($requestType == 'PATH_INFO')
  37. {
  38. $command = "$phpcli $binPath/ztcli '$pmsRoot/{$params['moduleName']}-{$params['methodName']}.html'";
  39. }
  40. else
  41. {
  42. $command = "$phpcli $binPath/ztcli '$pmsRoot/index.php?m={$params['moduleName']}&f={$params['methodName']}'";
  43. }
  44. $cronFile = strtolower($params['moduleName']) . strtolower($params['methodName']) . $suffix;
  45. file_put_contents($binPath . '/' . $cronFile, $command);
  46. $crond .= "{$cron->m} \t {$cron->h} \t {$cron->dom} \t {$cron->mon} \t {$cron->dow} \t $binPath/$cronFile \t #{$cron->remark}\n";
  47. echo "{$cronFile} ok.\n";
  48. }
  49. if(!is_dir("$binPath/cron")) mkdir("$binPath/cron", 0777, true);
  50. file_put_contents("$binPath/cron/sys.cron", $crond);
  51. file_put_contents("$binPath/cron" . $suffix, "$phpcli $binPath/php/crond.php\n");
  52. echo "cron{$suffix} ok\n";
  53. file_put_contents("$binPath/ztcli{$suffix}", "$phpcli $binPath/ztcli " . ($suffix == '.bat' ? '%' : '$') . "*\n");
  54. echo "ztcli{$suffix} ok\n";