| 1 |
<?php |
|---|
| 2 |
require_once(AMFPHP_BASE . "util/NetDebug.php"); |
|---|
| 3 |
require_once(AMFPHP_BASE . "adapters/lib/Arrayf.php"); |
|---|
| 4 |
|
|---|
| 5 |
class CachedExecutionAction |
|---|
| 6 |
{ |
|---|
| 7 |
function doAction (&$bodyObj) |
|---|
| 8 |
{ |
|---|
| 9 |
$className = str_replace('.php', '', str_replace('/', '.', $bodyObj->getUriClassPath())); |
|---|
| 10 |
$method = $bodyObj->getMethodName(); |
|---|
| 11 |
$args = $bodyObj->getValue(); |
|---|
| 12 |
|
|---|
| 13 |
if (!$bodyObj->getIgnoreExecution()) |
|---|
| 14 |
{ |
|---|
| 15 |
if($bodyObj->getIsDynamicPage()) |
|---|
| 16 |
{ |
|---|
| 17 |
$offset = $args[count($args) - 2] - 1; |
|---|
| 18 |
$limit = $args[count($args) -1]; |
|---|
| 19 |
array_splice($args, -2); |
|---|
| 20 |
} |
|---|
| 21 |
else |
|---|
| 22 |
{ |
|---|
| 23 |
$offset = 0; |
|---|
| 24 |
$limit = 3; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
try |
|---|
| 28 |
{ |
|---|
| 29 |
$records = $this->getRecords($className, $method, $args); |
|---|
| 30 |
} |
|---|
| 31 |
catch(Exception $fault) |
|---|
| 32 |
{ |
|---|
| 33 |
$ex = new AMFException(E_USER_ERROR, $fault->getMessage(), $fault->getFile(), $fault->getLine()); |
|---|
| 34 |
$records = '__amfphp_error'; |
|---|
| 35 |
AMFException::throwException($bodyObj, $ex); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
if($records !== '__amfphp_error') |
|---|
| 39 |
{ |
|---|
| 40 |
$dataSet = array_slice($records, $offset, $limit); |
|---|
| 41 |
$keys = array_keys($dataSet[0]); |
|---|
| 42 |
array_pop($keys); |
|---|
| 43 |
|
|---|
| 44 |
if($bodyObj->getIsDynamicPage()) |
|---|
| 45 |
{ |
|---|
| 46 |
$results = array("cursor" => $args[count($args) - 2] + 1, |
|---|
| 47 |
"data" => new Arrayf($dataSet, $keys)); |
|---|
| 48 |
$bodyObj->setType("__DYNAMIC_PAGE__"); |
|---|
| 49 |
} |
|---|
| 50 |
else |
|---|
| 51 |
{ |
|---|
| 52 |
$results = array('class' => $bodyObj->getUriClassPath(), |
|---|
| 53 |
'method' => $bodyObj->getMethodName(), |
|---|
| 54 |
'count' => count($records), |
|---|
| 55 |
"args" => $args, |
|---|
| 56 |
"data" => new Arrayf($dataSet, $keys)); |
|---|
| 57 |
$bodyObj->setType('__DYNAMIC_PAGEABLE_RESULTSET__'); |
|---|
| 58 |
} |
|---|
| 59 |
$bodyObj->setResults($results); |
|---|
| 60 |
$bodyObj->setResponseURI($bodyObj->getResponseIndex() . "/onResult"); |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
else |
|---|
| 64 |
{ |
|---|
| 65 |
if($bodyObj->getIsDynamicPage()) |
|---|
| 66 |
{ |
|---|
| 67 |
$bodyObj->setResults(true); |
|---|
| 68 |
$bodyObj->setType('boolean'); |
|---|
| 69 |
$bodyObj->setResponseURI($bodyObj->getResponseIndex() . "/onResult"); |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
return true; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
function getRecords($className, $method, $args) |
|---|
| 76 |
{ |
|---|
| 77 |
$sig = array( |
|---|
| 78 |
'className' => $className, |
|---|
| 79 |
'method' => $method, |
|---|
| 80 |
'args' => $args); |
|---|
| 81 |
$key = md5(serialize($sig)); |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
mysql_pconnect('localhost', 'root', ''); |
|---|
| 85 |
mysql_select_db('wcd'); |
|---|
| 86 |
$rs = mysql_query(sprintf("SELECT * FROM wcd_cache where sig = '%s'", $key)); |
|---|
| 87 |
$row = mysql_fetch_assoc($rs); |
|---|
| 88 |
$count = mysql_num_rows($rs); |
|---|
| 89 |
|
|---|
| 90 |
if($count == 1) |
|---|
| 91 |
{ |
|---|
| 92 |
|
|---|
| 93 |
$rows = unserialize($row['results']); |
|---|
| 94 |
return $rows; |
|---|
| 95 |
} |
|---|
| 96 |
else |
|---|
| 97 |
{ |
|---|
| 98 |
throw new Exception("Not found in cache: " . serialize($sig)); |
|---|
| 99 |
return false; |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
?> |
|---|