root/trunk/midgard/tools/midrepository/spool.php.in

Revision 7101, 3.7 kB (checked in by bergius, 5 years ago)

Initial commit of the MidRepository? workflow extension
Issue number:
Obtained from:
Submitted by:
Reviewed by:

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?
2 define('DEBUG', 1);
3 define('THIS_MGDDB', 1);
4
5 require_once 'paths.php';
6 require_once 'vcconfig.php';
7 require_once 'DataWorkFlow.php';
8
9 mgd_auth_midgard($rootuser, $rootpwd, false);
10 $midgard = mgd_get_midgard();
11
12 $host = mgd_get_host($midgard->host);
13 if ($host->port == 80) {
14   define ('LOCK', '/tmp/spool.lock.LIVE');
15   require_once 'live.php';
16 } else {
17   define ('LOCK', '/tmp/spool.lock.HEAD');
18   require_once 'staging.php';
19 }
20
21 /* function mtimeCmp($f1, $f2) {
22   return (filemtime($f1) < filemtime($f2))?-1:1;
23 }*/
24
25 function microtimeCmp($f1, $f2) {
26   $b1 = basename($f1);
27   $b2 = basename($f2);
28   $chunks1 = explode('.', $b1);
29   $chunks2 = explode('.', $b2);
30   return ($chunks1[1] > $chunks2[1])?1:-1;
31 }
32
33 if (@stat(LOCK)) {
34   die( "Spool busy.");
35 }
36
37 touch(LOCK);
38
39 wfInit();
40 $vcs = VCSessionRegistry::getDefaultVCSession();
41
42 /** first handle status for "not current" parts / wf-procs **/
43 $parts = MgdPart::searchNotCurrent();
44 if (is_array($parts)) {
45   foreach ($parts as $part) {
46     $myPart = MgdPart::readById($part);
47     echo "<h2>HANDLE PENDING PART " . $myPart->getGuid() . "</h2>";
48     $myPart->handleStatus();
49   }
50 }
51
52 $procs = WorkflowProc::searchNotCurrent();
53 if (is_array($procs)) {
54   foreach ($procs as $proc) {
55     echo "<h2>HANDLE PENDING WFPROC " . $proc . "</h2>";
56     $myProc = WorkflowProc::readById($proc);
57     $myProc->handleStatus();
58   }
59 }
60
61 $MgdDB = $vcs->getMgdDB();
62 $allnewfiles = array();
63 $d = dir($VCSessionConf['fsconf']['incoming']);
64 while (false !== ($dent = $d->read())) {
65   if ($dent == '..' or $dent == '.')
66     continue;
67   $fullname = $VCSessionConf['fsconf']['incoming'] . "/$dent";
68   if (@stat("$fullname.lock"))
69     continue;
70   $author = substr($dent, 0, 32);
71   if (!is_guid($author)) {
72     continue;
73   }
74   echo "HIER: $fullname";flush();
75   $archive = new MgdArchive($fullname);
76   if (is_object($archive)) {
77     $allnewfiles[$author][] = $fullname;
78   }
79   echo $dent."<br>\n";
80 }
81 $d->close(); 
82
83 //ob_implicit_flush();
84 foreach($allnewfiles as $author => $newfiles) {
85   print_r($newfiles);
86   usort($newfiles, 'microtimeCmp');
87   foreach($newfiles as $newfile) {
88     echo "<h2>HANDLE INCOMING FILE " . $newfile . "</h2>";
89     echo "<br><br><br>ARCHIVE: $newfile<br>";
90     $archive = new MgdArchive($newfile);
91     if (is_object($archive)) {
92       echo "JUHU, ICH BIN WIRKLICH EIN ARCHIV.<br>";
93       $guids = $archive->listGuids();
94       if (!is_array($guids)) {
95         $archive->deleteFile();
96         continue;
97       }
98       echo "FOLGENDE GUIDS NENNE ICH MEIN: ";
99       var_dump($guids);
100       echo "<br>";
101       $newguids = MgdPart::searchNewGuids($guids);
102       echo "DAVON SIND FOLGENDE NEU: ";
103       var_dump($newguids);
104       echo "<br>";
105       if (is_array($newguids)) {
106         foreach($newguids as $newguid) {
107           $part = MgdPart::brew($newguid, PART_NEW_DB);
108           $part->write();
109           echo "LOCKING NEW OBJ " . $newguid . "<br>";
110           $part->lock();
111         }
112       }
113       $parts = array();
114       foreach($guids as $guid) {
115         $parts[] = MgdPart::readByGuid($guid);
116       }
117       $current = true;
118       foreach($parts as $part) {
119         if ($part->getStatus() != PART_CURRENT) {
120           if (!in_array($guid, $newguids)) {
121             $current = false;
122             break;
123           }
124         } else {
125           echo "LOCKING OLD OBJ " . $part->getGuid() . "<br>";
126           $part->lock();
127         }
128       }
129       if ($current) {
130         $MgdDB->importKeepDeleted($archive);
131         $archive->deleteFile();
132         foreach ($parts as $part) {
133           echo "<b>";
134           echo $MgdDB->get_path_by_guid($part->getGuid());
135           echo "</b><br>";
136           $part->setStatus(PART_NEW_DB, $author);
137         }
138         echo "KLINK 4.";
139       }
140       foreach($parts as $part) {
141         echo "UNLOCKING OBJ " . $part->getGuid() . "<br>";
142         $part->unlock();
143         echo "RETURN : " . $part->handleStatus();
144       }
145     }
146   }
147 }
148
149 /* $log = ob_get_contents();
150 $fp = fopen ('/var/mgd/spool.log', 'a');
151 fwrite($fp, $log);
152 fclose($fp);
153 ob_end_flush();
154 */
155 unlink(LOCK);
156
157 ?>
Note: See TracBrowser for help on using the browser.