PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/cron.php

https://bitbucket.org/mkrasuski/magento-ce
PHP | 83 lines | 46 code | 10 blank | 27 comment | 11 complexity | a5087282b32d81c52fccc65a54444fd5 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. // Change current directory to the directory of current script
  27. chdir(dirname(__FILE__));
  28. require 'app/bootstrap.php';
  29. require 'app/Mage.php';
  30. if (!Mage::isInstalled()) {
  31. echo "Application is not installed yet, please complete install wizard first.";
  32. exit;
  33. }
  34. // Only for urls
  35. // Don't remove this
  36. $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
  37. $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);
  38. Mage::app('admin')->setUseSessionInUrl(false);
  39. umask(0);
  40. $disabledFuncs = explode(',', ini_get('disable_functions'));
  41. $isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
  42. $isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
  43. try {
  44. if (stripos(PHP_OS, 'win') === false) {
  45. $options = getopt('m::');
  46. if (isset($options['m'])) {
  47. if ($options['m'] == 'always') {
  48. $cronMode = 'always';
  49. } elseif ($options['m'] == 'default') {
  50. $cronMode = 'default';
  51. } else {
  52. Mage::throwException('Unrecognized cron mode was defined');
  53. }
  54. } else if (!$isShellDisabled) {
  55. $fileName = escapeshellarg(basename(__FILE__));
  56. $cronPath = escapeshellarg(dirname(__FILE__) . '/cron.sh');
  57. shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -mdefault 1 > /dev/null 2>&1 &"));
  58. shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -malways 1 > /dev/null 2>&1 &"));
  59. exit;
  60. }
  61. }
  62. Mage::getConfig()->init()->loadEventObservers('crontab');
  63. Mage::app()->addEventArea('crontab');
  64. if ($isShellDisabled) {
  65. Mage::dispatchEvent('always');
  66. Mage::dispatchEvent('default');
  67. } else {
  68. Mage::dispatchEvent($cronMode);
  69. }
  70. } catch (Exception $e) {
  71. Mage::printException($e);
  72. exit(1);
  73. }