/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to system/downloads_check.php

  • Committer: Suren A. Chilingaryan
  • Date: 2011-03-15 02:47:05 UTC
  • mfrom: (210.1.3 adei)
  • Revision ID: csa@dside.dyndns.org-20110315024705-qljn30gwin8yrkne
Integration of work of students with fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
//   $res = exec('ps xa | grep "downloads_check.php" | grep -v grep | wc -l');
 
5
//   if ($res > 1) exit;
 
6
 
 
7
  if (preg_match("/(.*)downloads_check.php$/", $_SERVER['SCRIPT_FILENAME'], $m)) @chdir($m[1]);
 
8
  require("../adei.php"); 
 
9
 
 
10
  $lock = new LOCK("downloads_check");
 
11
  $lock->Lock(LOCK::BLOCK);
 
12
 
 
13
  global $ADEI;
 
14
  global $ADEI_ROOTDIR;
 
15
  $ADEI->RequireClass("download");      
 
16
 
 
17
  $cache = new CACHEDB();
 
18
  $dm = new DOWNLOADMANAGER(); 
 
19
  $res = $cache->GetDownloads("","ASC");        
 
20
 
 
21
  while($row = mysql_fetch_array($res)) {
 
22
    $status = $row['status'];
 
23
    $name = $dm->Getfilename($download); 
 
24
    $file = $ADEI_ROOTDIR."tmp/downloads/".$name;
 
25
    $fsize = filesize($file);   
 
26
    $lastmodified = time() - filemtime($file);
 
27
    if($fsize > 1 && $lastmodified > 1) $this->ChangeStatus($row['dl_id'], 'Ready');
 
28
    if($status == "Preparing" || $status == "Finalizing") {
 
29
      $busy = 1;
 
30
    }
 
31
    if($nextdownload == "" && $status == "Queue"){
 
32
      $nextdownload = $row['dl_id'];    
 
33
    }
 
34
  }    
 
35
  
 
36
  
 
37
  if($nextdownload != "" && $busy != 1) {
 
38
    try {
 
39
      $opts = $dm->CreateDataRequestOpts($nextdownload); 
 
40
      $dm->DataRequest($opts);
 
41
    } catch(ADEIException $ex) {   
 
42
      //$dm->Logit($ex->getMessage());      
 
43
      $dm->ChangeStatus($nextdownload, "ERROR");
 
44
      $dm->SetError($nextdownload, $ex->getMessage());                
 
45
    }
 
46
  }
 
47
  
 
48
 
 
49
  $lock->UnLock();
 
50
  unset($lock);
 
51
 
 
52
?>
 
 
b'\\ No newline at end of file'