18 |
* $Id$ |
* $Id$ |
19 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
20 |
* $Log$ |
* $Log$ |
21 |
|
* Revision 1.20 2004/06/20 23:03:34 joko |
22 |
|
* minor fix: don't resolve result-status as "good", if server-status contains errors |
23 |
|
* |
24 |
|
* Revision 1.19 2004/06/07 16:56:45 joko |
25 |
|
* enabled caching-layers |
26 |
|
* minor fixes regarding caching |
27 |
|
* |
28 |
|
* Revision 1.18 2004/05/13 19:17:55 jonen |
29 |
|
* + bugfix: utf8 conversion was missing at some backend-calls |
30 |
|
* |
31 |
|
* Revision 1.17 2003/07/14 10:05:23 jonen |
32 |
|
* bugfix: added *needed* function 'getAttributes' |
33 |
|
* |
34 |
|
* Revision 1.16 2003/07/02 13:51:38 jonen |
35 |
|
* removed debug dumper |
36 |
|
* |
37 |
|
* Revision 1.15 2003/04/11 01:32:21 joko |
38 |
|
* renamed logging function |
39 |
|
* |
40 |
|
* Revision 1.14 2003/04/09 02:06:45 joko |
41 |
|
* errormessage now shown preformatted |
42 |
|
* |
43 |
* Revision 1.13 2003/04/04 17:38:03 joko |
* Revision 1.13 2003/04/04 17:38:03 joko |
44 |
* modifications regarding error-/exception-handling and -tracing |
* modifications regarding error-/exception-handling and -tracing |
45 |
* |
* |
288 |
var $backend; |
var $backend; |
289 |
|
|
290 |
function DesignPattern_RemoteProxy($objectId = "", $options = array() ) { |
function DesignPattern_RemoteProxy($objectId = "", $options = array() ) { |
291 |
logp(get_class($this) . "->new()", PEAR_LOG_INFO); |
php::log(get_class($this) . "->new(objectId=$objectId)", PEAR_LOG_INFO); |
292 |
global $proxy; |
global $proxy; |
293 |
|
|
294 |
// 2003-03-05 - modified constructor |
// 2003-03-05 - modified constructor |
352 |
|
|
353 |
|
|
354 |
function load() { |
function load() { |
355 |
logp(get_class($this) . "->load()", PEAR_LOG_INFO); |
php::log(get_class($this) . "->load()", PEAR_LOG_INFO); |
356 |
if (!$this->_loadState()) { |
if (!$this->_loadState()) { |
357 |
if (!$this->_loadProxy()) { |
if (!$this->_loadProxy()) { |
358 |
|
|
409 |
$this->attributes = $data; |
$this->attributes = $data; |
410 |
} |
} |
411 |
|
|
412 |
|
function getAttributes() { |
413 |
|
return $this->attributes; |
414 |
|
} |
415 |
|
|
416 |
function flushProxy() { |
function flushProxy() { |
417 |
connectdb(); |
connectdb(); |
418 |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
428 |
function _loadState() { |
function _loadState() { |
429 |
global $proxy; |
global $proxy; |
430 |
|
|
431 |
|
// just do session-caching if requested |
432 |
|
if (!$this->meta[cache][session]) { return; } |
433 |
|
|
434 |
// trace |
// trace |
435 |
//print Dumper($this); |
//print Dumper($this); |
436 |
|
|
437 |
// debug |
// debug |
438 |
logp(get_class($this) . "->_loadState()"); |
php::log(get_class($this) . "->_loadState()"); |
439 |
|
|
440 |
if ($this->attributes = $proxy[$this->objectId]) { |
if ($this->attributes = $proxy[$this->objectId]) { |
441 |
//print "_loadState:" . dumpVar($this->attributes); |
//print "_loadState:" . dumpVar($this->attributes); |
442 |
$this->meta[decoded] = 1; |
$this->meta[decoded] = 1; |
443 |
// TODO: make a parameter from this (0 deactivates session-layer) |
// TODO: make a parameter from this (0 deactivates session-layer) |
444 |
return 0; |
return 1; |
445 |
} |
} |
446 |
} |
} |
447 |
|
|
448 |
function _saveState() { |
function _saveState() { |
449 |
global $proxy; |
global $proxy; |
450 |
logp(get_class($this) . "->_saveState()"); |
|
451 |
|
// just do session-caching if requested |
452 |
|
if (!$this->meta[cache][session]) { return; } |
453 |
|
|
454 |
|
php::log(get_class($this) . "->_saveState()"); |
455 |
$proxy[$this->objectId] = $this->attributes; |
$proxy[$this->objectId] = $this->attributes; |
456 |
//print "_saveState: " . dumpVar($this->attributes); |
//print "_saveState: " . dumpVar($this->attributes); |
457 |
// TODO: throw exception-message back to user if operation fails |
// TODO: throw exception-message back to user if operation fails |
464 |
|
|
465 |
// trace & debug |
// trace & debug |
466 |
//print Dumper($this); |
//print Dumper($this); |
467 |
logp(get_class($this) . "->_loadProxy()"); |
php::log(get_class($this) . "->_loadProxy()"); |
468 |
|
|
469 |
connectdb(); |
connectdb(); |
470 |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
473 |
if ($row) { |
if ($row) { |
474 |
$this->payload = $row[payload]; |
$this->payload = $row[payload]; |
475 |
// TODO: make a parameter from this (0 deactivates mysqldb-layer) |
// TODO: make a parameter from this (0 deactivates mysqldb-layer) |
476 |
return 0; |
return 1; |
477 |
} |
} |
478 |
} |
} |
479 |
} |
} |
484 |
// FIXME! |
// FIXME! |
485 |
if (!$this->meta[cache][db]) { return; } |
if (!$this->meta[cache][db]) { return; } |
486 |
|
|
487 |
logp(get_class($this) . "->_saveProxy()"); |
php::log(get_class($this) . "->_saveProxy()"); |
488 |
connectdb(); |
connectdb(); |
489 |
if ($this->payload) { |
if ($this->payload) { |
490 |
//$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'"; |
//$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'"; |
497 |
} |
} |
498 |
|
|
499 |
function _loadRemote() { |
function _loadRemote() { |
500 |
logp(get_class($this) . "->_loadRemote()"); |
php::log(get_class($this) . "->_loadRemote()"); |
501 |
|
|
502 |
// trace |
// trace |
503 |
//print Dumper($this->meta); |
//print Dumper($this->meta); |
506 |
|
|
507 |
// 1. check backend-handle |
// 1. check backend-handle |
508 |
if (!$this->backend) { |
if (!$this->backend) { |
509 |
logp(get_class($this) . "->_loadRemote: no backend handle, please check argument 'rpcinfo'", PEAR_LOG_CRIT); |
php::log(get_class($this) . "->_loadRemote: no backend handle, please check argument 'rpcinfo'", PEAR_LOG_CRIT); |
510 |
return; |
return; |
511 |
} |
} |
512 |
|
|
514 |
// check for guid or oid |
// check for guid or oid |
515 |
if ($this->meta[guid]) { |
if ($this->meta[guid]) { |
516 |
if (!$this->objectId) { |
if (!$this->objectId) { |
517 |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires valid objectId", PEAR_LOG_WARNING); |
php::log(get_class($this) . "->_loadRemote: argument 'guid' requires valid objectId", PEAR_LOG_WARNING); |
518 |
return; |
return; |
519 |
} |
} |
520 |
if (!$this->meta[classname]) { |
if (!$this->meta[classname]) { |
521 |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
php::log(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
522 |
return; |
return; |
523 |
} |
} |
524 |
logp(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG); |
php::log(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG); |
525 |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
526 |
$result = $this->backend->send('getObjectByGuid', $args ); |
$result = $this->backend->send('getObjectByGuid', $args, array( utf8 => 1) ); |
527 |
|
|
528 |
} elseif ($this->meta[oid]) { |
} elseif ($this->meta[oid]) { |
529 |
if (!$this->objectId) { |
if (!$this->objectId) { |
530 |
logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING); |
php::log(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING); |
531 |
return; |
return; |
532 |
} |
} |
533 |
logp(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG); |
php::log(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG); |
534 |
$result = $this->backend->send('getObject', $this->objectId); |
$result = $this->backend->send('getObject', $this->objectId, array( utf8 => 1) ); |
535 |
|
|
536 |
} elseif ($this->meta[key]) { |
} elseif ($this->meta[key]) { |
537 |
if (!$this->meta[command]) { |
if (!$this->meta[command]) { |
538 |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING); |
php::log(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING); |
539 |
return; |
return; |
540 |
} |
} |
541 |
/* |
/* |
542 |
if (!$this->meta[query]) { |
if (!$this->meta[query]) { |
543 |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING); |
php::log(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING); |
544 |
return; |
return; |
545 |
} |
} |
546 |
*/ |
*/ |
547 |
//logp(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG); |
//php::log(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG); |
548 |
//print Dumper(array($this->meta[command], $this->meta[query])); |
//print Dumper(array($this->meta[command], $this->meta[query])); |
549 |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
$result = $this->backend->send($this->meta[command], $this->meta[query], array( utf8 => 1) ); |
550 |
|
|
551 |
} |
} |
552 |
|
|
555 |
$status = $this->backend->status(); |
$status = $this->backend->status(); |
556 |
//print Dumper($status); |
//print Dumper($status); |
557 |
|
|
558 |
$good = is_array($result) && sizeof($result) && $status[connected]; |
$good = !$status[errors] && is_array($result) && sizeof($result) && $status[connected]; |
559 |
|
|
560 |
if ($good) { |
if ($good) { |
561 |
|
|
593 |
$statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() ); |
$statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() ); |
594 |
$statusbox->add( html_span('boxlabel_yellow', "RPCSESSID:"), $status[RPCSESSID], html_br() ); |
$statusbox->add( html_span('boxlabel_yellow', "RPCSESSID:"), $status[RPCSESSID], html_br() ); |
595 |
foreach ($status[errors] as $error) { |
foreach ($status[errors] as $error) { |
596 |
$statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $error[message], html_br() ); |
$msg = html_pre($error[message]); |
597 |
|
$statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $msg ); |
598 |
} |
} |
599 |
|
|
600 |
$message = "Error while talking to remote side. Please check wire, socket or api."; |
$message = "Error while talking to remote side. Please check wire, socket or api."; |
601 |
logp($message, PEAR_LOG_CRIT); |
php::log($message, PEAR_LOG_CRIT); |
602 |
$statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() ); |
$statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() ); |
603 |
|
|
604 |
// V1 |
// V1 |
620 |
|
|
621 |
|
|
622 |
function _saveBackend($result) { |
function _saveBackend($result) { |
623 |
logp(get_class($this) . "->_saveBackend()"); |
php::log(get_class($this) . "->_saveBackend()"); |
624 |
|
|
625 |
//$encoder = new TextEncode($result); |
//$encoder = new TextEncode($result); |
626 |
//$encoder->toUTF8(); |
//$encoder->toUTF8(); |
651 |
|
|
652 |
} |
} |
653 |
|
|
|
?> |
|
654 |
|
?> |