Changeset 729


Ignore:
Timestamp:
Jan 12, 2015, 12:20:30 AM (10 years ago)
Author:
chronos
Message:
  • Added: Generic Scheduler module for running tasks on specified time and with specified period.
  • Added: System execution from command line using cmd.php entry point.
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/System.php

    r657 r729  
    2424  var $ShowPage;
    2525  var $Setup;
     26  var $CommandLine;
    2627
    2728  function __construct()
     
    3839    if(substr($this->RootURLFolder, -10, 10) == '/index.php')
    3940      $this->RootURLFolder = substr($this->RootURLFolder, 0, -10);
     41    $this->CommandLine = array();
    4042  }
    4143
     
    132134  }
    133135
    134   function Run()
     136  function RunCommon()
    135137  {
    136138        global $Database, $ScriptTimeStart, $ConfigFileName, $Mail, $Type,
     
    177179    if($this->Setup->CheckState())
    178180    {
    179       $this->ModuleManager->Start();
    180     }
     181      $this->ModuleManager->Start();   
     182    }
     183  }
     184 
     185  function Run()
     186  {
     187    $this->RunCommon();
    181188    if($this->ShowPage)
    182189    {
     
    186193  }
    187194
     195  function RunCommandLine()
     196  {
     197        global $argv;
     198       
     199        $this->RunCommon();
     200        if(count($argv) > 1)
     201        {
     202      if(array_key_exists($argv[1], $this->CommandLine))
     203      {
     204        $Command = $this->CommandLine[$argv[1]];
     205        if(is_string($Command['Callback'][0]))
     206              {
     207                $Class = new $Command['Callback'][0]($this);
     208                $Output = $Class->$Command['Callback'][1]();           
     209              } else $Output = call_user_func($Command['Callback']);
     210              echo($Output);
     211      } else echo('Command "'.$argv[1].'" not supported.'."\n");       
     212        }
     213        //print_r($argv);
     214  }
     215 
     216  function RegisterCommandLine($Name, $Callback)
     217  {
     218        $this->CommandLine[$Name] = array('Name' => $Name, 'Callback' => $Callback);
     219  }
     220 
    188221  function RegisterPageBar($Name)
    189222  {
  • trunk/Application/Version.php

    r728 r729  
    11<?php
    22
    3 $Revision = 728; // Subversion revision
    4 $DatabaseRevision = 726; // SQL structure revision
    5 $ReleaseTime = strtotime('2015-01-05');
     3$Revision = 729; // Subversion revision
     4$DatabaseRevision = 729; // SQL structure revision
     5$ReleaseTime = strtotime('2015-01-11');
  • trunk/Common/Global.php

    r727 r729  
    443443  if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
    444444  $PathItems = explode('/', $PathString);
    445   if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
     445  if(array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))
    446446    $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
    447447    else $_SERVER['QUERY_STRING'] = '';
  • trunk/Common/Page.php

    r635 r729  
    5050  function ShowHeader($Title, $Path)
    5151  {
    52     $ScriptName = $_SERVER['REQUEST_URI'];
     52        if(array_key_exists('REQUEST_URI', $_SERVER))
     53      $ScriptName = $_SERVER['REQUEST_URI'];
     54          else $ScriptName = '';
    5355    while(strpos($ScriptName, '//') !== false)
    5456      $ScriptName = str_replace('//', '/', $ScriptName);
  • trunk/Common/Setup/Updates.php

    r726 r729  
    11701170       
    11711171        $Manager->Execute('ALTER TABLE `MemberPayment` DROP `NetworkDevice`;');
     1172}
     1173
     1174function UpdateTo729($Manager)
     1175{
     1176 $Manager->Execute('ALTER TABLE `FinanceBankAccount` ADD `AutoImport` INT NOT NULL ;');
     1177 
     1178  $Manager->Execute('CREATE TABLE IF NOT EXISTS `Scheduler` (
     1179  `Id` int(11) NOT NULL,
     1180  `Name` varchar(255) NOT NULL,
     1181  `Enabled` int(11) NOT NULL,
     1182  `Class` varchar(255) NOT NULL,
     1183  `Log` mediumtext NOT NULL,
     1184  `LastExecutedTime` datetime DEFAULT NULL,
     1185  `ScheduledTime` datetime NOT NULL,
     1186  `Period` int(11) NOT NULL
     1187) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
     1188
     1189  $Manager->Execute('ALTER TABLE `Scheduler`
     1190 ADD PRIMARY KEY (`Id`);');
     1191 
     1192  $Manager->Execute('ALTER TABLE `Scheduler`
     1193MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT;');
     1194
     1195  // IS menu item
     1196  $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     1197`Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     1198NULL , "", "Plánovač", "1", "/is/?t=Scheduler&a=list", NULL , NULL , NULL , "1");');
     1199  $ActionId = $Manager->Database->insert_id;
     1200  $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Systém"');
     1201  if($DbResult->num_rows > 0)
     1202  {
     1203        $DbRow = $DbResult->fetch_assoc();
     1204    $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     1205      "VALUES (NULL , 'Plánovač', ".$DbRow['Id'].", '".$ActionId."', '1');");
     1206  }
     1207 
     1208  $Manager->Execute('INSERT INTO `Module` (`Id`, `Name`, `Title`) VALUES (NULL, "Plánovač", "Scheduler");');
    11721209}
    11731210
     
    12331270        722 => array('Revision' => 725, 'Function' => 'UpdateTo725'),
    12341271        725 => array('Revision' => 726, 'Function' => 'UpdateTo726'),
     1272        726 => array('Revision' => 729, 'Function' => 'UpdateTo729'),
    12351273    ));
    12361274  }
  • trunk/Modules/Finance/Finance.php

    r728 r729  
    380380          'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT SUM(`FinanceOperation`.`Value` * `FinanceOperation`.`Direction`) FROM `FinanceOperation` '.
    381381          'WHERE `FinanceOperation`.`BankAccount`=#Id)'),
     382        'AutoImport' => array('Type' => 'Boolean', 'Caption' => 'Automaticky stahovat z banky', 'Default' => ''),
    382383      ),
    383384      'ItemActions' => array(
  • trunk/Modules/FinanceBankAPI/FinanceBankAPI.php

    r639 r729  
    44include_once(dirname(__FILE__).'/ImportPS.php');
    55include_once(dirname(__FILE__).'/ImportFio.php');
     6include_once(dirname(__FILE__).'/../Scheduler/Scheduler.php');
    67
    78class ModuleFinanceBankAPI extends AppModule
     
    1516    $this->License = 'GNU/GPLv3';
    1617    $this->Description = 'Communication through API to various banks, manual file import';
    17     $this->Dependencies = array('Finance');
     18    $this->Dependencies = array('Finance', 'Scheduler');
    1819  }
    1920
     
    5859
    5960    $this->System->RegisterPage(array('finance', 'import-api'), 'PageImportAPI');
    60     $this->System->RegisterPage(array('finance', 'import-soubor'), 'PageImportFile');
     61    $this->System->RegisterPage(array('finance', 'import-soubor'), 'PageImportFile');   
    6162  }
    6263
     
    8182  }
    8283}
     84
     85class ScheduleBankImport extends SchedulerTask
     86{
     87        function Execute()
     88        {
     89                $Output = '';
     90                $DbResult = $this->Database->select('FinanceBankAccount', 'Id', '(AutoImport=1) AND ((TimeEnd IS NULL) OR (TimeEnd > NOW()))');
     91                while($DbRow = $DbResult->fetch_assoc())
     92                {                       
     93                        $Page = new PageImportAPI($this->System);
     94                        $Output .= $Page->Show();
     95                }
     96                return($Output);
     97        }
     98}
  • trunk/Modules/User/User.php

    r711 r729  
    6666    $this->OnlineStateTimeout = 600; // in seconds
    6767    $this->PasswordHash = new PasswordHash();
     68    $this->User = array('Id' => null, 'Member' => null);
    6869  }
    6970
     
    694695  function TopBarCallback()
    695696  {
    696     if($this->System->User->User['Id'] == null)
     697    if($this->System->User->User['Id'] == null)
     698    {
    697699      $Output = '<a href="'.$this->System->Link('/user/?Action=LoginForm').'">Přihlášení</a> '.
    698700        '<a href="'.$this->System->Link('/user/?Action=UserRegister').'">Registrace</a>';
    699       else $Output = $this->System->User->User['Name'].
     701    } else
     702    {
     703        $Output = $this->System->User->User['Name'].
    700704        ' <a href="'.$this->System->Link('/user/?Action=UserMenu').'">Nabídka</a>'.
    701705        ' <a href="'.$this->System->Link('/user/?Action=Logout').'">Odhlásit</a>';
    702 //   <a href="'.$this->System->Link('/?Action=UserOptions').'">Nastavení</a>';
     706        //   <a href="'.$this->System->Link('/?Action=UserOptions').'">Nastavení</a>';
     707    }
    703708    return($Output);
    704709  }
Note: See TracChangeset for help on using the changeset viewer.