Paypal GetExpressCheckoutDetails missing PAYERID - paypal

( see https://developer.paypal.com/docs/integration/direct/identity/seamless-checkout/ )
We log the user in via OpenID (Log In With PayPal) and receive an access token.
We call SetExpressCheckout giving the IDENTITYACCESSTOKEN
We call GetExpressCheckoutDetails and expect the PAYERID to be populated. It does not exist in the response.
I cannot call DoExpressCheckoutPayment without having the PAYERID.
I have attached the request/response data below.
Notice that GetExpressCheckoutDetails does not contain PAYERID.
Why might this be happening?
Thanks!
SetExpressCheckout Request:
array (size=23)
'METHOD' => string 'SetExpressCheckout' (length=18)
'PAYMENTREQUEST_0_ITEMAMT' => string '329.00' (length=6)
'PAYMENTREQUEST_0_AMT' => string '329.00' (length=6)
'PAYMENTREQUEST_0_TAXAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_SHIPPINGAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_CURRENCYCODE' => string 'USD' (length=3)
'RETURNURL' => string 'https://some.url/' (length=39)
'CANCELURL' => string 'https://some.url/' (length=25)
'VERSION' => string '106.0' (length=5)
'USER' => string 'secure-paypal_api1.somedomain.com' (length=30)
'PWD' => string 'XXXXXXXXXXXXXXXXX' (length=16)
'SIGNATURE' => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=56)
'NOSHIPPING' => string '1' (length=1)
'PAYMENTREQUEST_0_PAYMENTACTION' => string 'Sale' (length=4)
'HDRIMG' => string 'https://www.some.url/.jpg' (length=70)
'EMAIL' => string 'foo#foo.com' (length=23)
'CUSTOMERSERVICENUMBER' => string '1-111-111-1111' (length=14)
'ALLOWNOTE' => string '0' (length=1)
'IDENTITYACCESSTOKEN' => string '2nd3CS9HG1EWzTQGy6l.4n7CsilVWgkqn20bTuUfSXX' (length=43)
'L_PAYMENTREQUEST_0_NAME0' => string 'or3333' (length=6)
'L_PAYMENTREQUEST_0_AMT0' => string '329.00' (length=6)
'L_PAYMENTREQUEST_0_DESC0' => string 'Product name foobar' (length=31)
'L_PAYMENTREQUEST_0_QTY0' => string '1' (length=1)
SetExpressCheckout Response:
array (size=6)
'TOKEN' => string 'EC-4W147554UR614711B' (length=20)
'TIMESTAMP' => string '2014-01-17T20:41:50Z' (length=20)
'CORRELATIONID' => string '4ef48694990' (length=11)
'ACK' => string 'Success' (length=7)
'VERSION' => string '106.0' (length=5)
'BUILD' => string '9285531' (length=7)
GetExpressCheckoutDetails Request:
array (size=6)
'METHOD' => string 'GetExpressCheckoutDetails' (length=25)
'TOKEN' => string 'EC-4W147554UR614711B' (length=20)
'VERSION' => string '106.0' (length=5)
'USER' => string 'secure-paypal_api1.sylvane.com' (length=30)
'PWD' => string 'XXXXXXXXXXXXXXXX' (length=16)
'SIGNATURE' => string 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (length=56)
GetExpressCheckoutDetails Response:
array (size=44)
'TOKEN' => string 'EC-4W147554UR614711B' (length=20)
'CHECKOUTSTATUS' => string 'PaymentActionNotInitiated' (length=25)
'TIMESTAMP' => string '2014-01-17T20:41:50Z' (length=20)
'CORRELATIONID' => string '605766387f780' (length=13)
'ACK' => string 'Success' (length=7)
'VERSION' => string '106.0' (length=5)
'BUILD' => string '9285531' (length=7)
'CURRENCYCODE' => string 'USD' (length=3)
'AMT' => string '329.00' (length=6)
'ITEMAMT' => string '329.00' (length=6)
'SHIPPINGAMT' => string '0.00' (length=4)
'HANDLINGAMT' => string '0.00' (length=4)
'TAXAMT' => string '0.00' (length=4)
'INSURANCEAMT' => string '0.00' (length=4)
'SHIPDISCAMT' => string '0.00' (length=4)
'L_NAME0' => string 'or2395' (length=6)
'L_QTY0' => string '1' (length=1)
'L_TAXAMT0' => string '0.00' (length=4)
'L_AMT0' => string '329.00' (length=6)
'L_DESC0' => string 'Product name foobar' (length=31)
'L_ITEMWEIGHTVALUE0' => string ' 0.00000' (length=10)
'L_ITEMLENGTHVALUE0' => string ' 0.00000' (length=10)
'L_ITEMWIDTHVALUE0' => string ' 0.00000' (length=10)
'L_ITEMHEIGHTVALUE0' => string ' 0.00000' (length=10)
'PAYMENTREQUEST_0_CURRENCYCODE' => string 'USD' (length=3)
'PAYMENTREQUEST_0_AMT' => string '329.00' (length=6)
'PAYMENTREQUEST_0_ITEMAMT' => string '329.00' (length=6)
'PAYMENTREQUEST_0_SHIPPINGAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_HANDLINGAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_TAXAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_INSURANCEAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_SHIPDISCAMT' => string '0.00' (length=4)
'PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED' => string 'false' (length=5)
'PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS' => string 'None' (length=4)
'L_PAYMENTREQUEST_0_NAME0' => string 'or3333' (length=6)
'L_PAYMENTREQUEST_0_QTY0' => string '1' (length=1)
'L_PAYMENTREQUEST_0_TAXAMT0' => string '0.00' (length=4)
'L_PAYMENTREQUEST_0_AMT0' => string '329.00' (length=6)
'L_PAYMENTREQUEST_0_DESC0' => string 'Product name foobar' (length=31)
'L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0' => string ' 0.00000' (length=10)
'L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0' => string ' 0.00000' (length=10)
'L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0' => string ' 0.00000' (length=10)
'L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0' => string ' 0.00000' (length=10)
'PAYMENTREQUESTINFO_0_ERRORCODE' => string '0' (length=1)

Even when you pass the IDENTITYACCESSTOKEN in the SetExpressCheckout call, you still need to redirect the buyer over to PayPal so that they can approve the payment. Setting IDENTITYACCESSTOKEN allows the buyer to skip the login page, making the process quicker for them, but they still need to go over to PayPal to approve the payment. After you make your SetExpressCheckout call, redirect them to https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={token} (where {token} is the value of TOKEN from the SetExpressCheckout response).

Related

Symfony3.3 form name not in Request

Heads up - I've already been here. Strange issue with Symfony3 forms. So I've created FormType class:
class GetPostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->setMethod("POST")
->add('phrase', Type\TextType::class);
}
}
As you can see form is not bound to any entity or other object(this shouldn't matter though). Now when I try to handle incoming request with that form:
$postForm = $this->createForm(GetPostType::class);
$postForm->handleRequest($this->request);
... normally handleRequest should submit my form. However:
$postForm->isSubmitted();
is false.
I've tracked down source of issue to HttpFoundationRequestHandler.
} elseif ($request->request->has($name) || $request->files->has($name)) {
According to this my form name is not present in request. That's what I don't get. I'm using Symfony forms at work and there's no problem. I used them in different projects and it was ok. Now for some reason I can't get them to work. It is probably something obvious but I guess I need another pair of eyes to see it.
As you can see I did try to set form method manually(it should be POST by default) but it didn't work. I did clear the cache and stuff. I did try different things I found on the internet but no luck.
I can't find anything that might be the reason. Any ideas what it might be?
UPDATE:
As requested in comments section I provide dump of my request object.
So how do I know it is the right thing? It is accepted by handleRequest method witch expects request type and it contains correct data.
/var/www/story/src/CodeCraft/BlogBundle/Controller/Api/PostController.php:73:
object(Symfony\Component\HttpFoundation\Request)[49]
public 'attributes' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[12]
protected 'parameters' =>
array (size=4)
'_controller' => string 'CodeCraft\BlogBundle\Controller\Api\PostController::getPostsAction' (length=66)
'_route' => string 'blog.api.posts.get' (length=18)
'_route_params' =>
array (size=0)
...
'_firewall_context' => string 'security.firewall.map.context.main' (length=34)
public 'request' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[10]
protected 'parameters' =>
array (size=1)
'phrase' => string 'xxx' (length=3)
public 'query' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[11]
protected 'parameters' =>
array (size=0)
empty
public 'server' =>
object(Symfony\Component\HttpFoundation\ServerBag)[15]
protected 'parameters' =>
array (size=34)
'HTTP_CACHE_CONTROL' => string 'no-cache' (length=8)
'HTTP_POSTMAN_TOKEN' => string '2eea2285-a2f7-4ca5-a799-ea97758d7d20' (length=36)
'CONTENT_TYPE' => string 'application/x-www-form-urlencoded' (length=33)
'HTTP_USER_AGENT' => string 'PostmanRuntime/6.1.6' (length=20)
'HTTP_ACCEPT' => string '*/*' (length=3)
'HTTP_HOST' => string 'story.dev' (length=9)
'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate' (length=13)
'CONTENT_LENGTH' => string '10' (length=2)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'PATH' => string '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' (length=60)
'SERVER_SIGNATURE' => string '<address>Apache/2.4.18 (Ubuntu) Server at story.dev Port 80</address>
' (length=70)
'SERVER_SOFTWARE' => string 'Apache/2.4.18 (Ubuntu)' (length=22)
'SERVER_NAME' => string 'story.dev' (length=9)
'SERVER_ADDR' => string '192.168.33.10' (length=13)
'SERVER_PORT' => string '80' (length=2)
'REMOTE_ADDR' => string '192.168.33.1' (length=12)
'DOCUMENT_ROOT' => string '/var/www/story/web' (length=18)
'REQUEST_SCHEME' => string 'http' (length=4)
'CONTEXT_PREFIX' => string '' (length=0)
'CONTEXT_DOCUMENT_ROOT' => string '/var/www/story/web' (length=18)
'SERVER_ADMIN' => string 'webmaster#localhost' (length=19)
'SCRIPT_FILENAME' => string '/var/www/story/web/app_dev.php' (length=30)
'REMOTE_PORT' => string '57039' (length=5)
'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
'REQUEST_METHOD' => string 'POST' (length=4)
'QUERY_STRING' => string '' (length=0)
'REQUEST_URI' => string '/app_dev.php/posts' (length=18)
'SCRIPT_NAME' => string '/app_dev.php' (length=12)
'PATH_INFO' => string '/posts' (length=6)
'PATH_TRANSLATED' => string '/var/www/story/web/posts' (length=24)
'PHP_SELF' => string '/app_dev.php/posts' (length=18)
'REQUEST_TIME_FLOAT' => float 1509896560.734
'REQUEST_TIME' => int 1509896560
public 'files' =>
object(Symfony\Component\HttpFoundation\FileBag)[14]
protected 'parameters' =>
array (size=0)
empty
public 'cookies' =>
object(Symfony\Component\HttpFoundation\ParameterBag)[13]
protected 'parameters' =>
array (size=0)
empty
public 'headers' =>
object(Symfony\Component\HttpFoundation\HeaderBag)[16]
protected 'headers' =>
array (size=10)
'cache-control' =>
array (size=1)
...
'postman-token' =>
array (size=1)
...
'content-type' =>
array (size=1)
...
'user-agent' =>
array (size=1)
...
'accept' =>
array (size=1)
...
'host' =>
array (size=1)
...
'accept-encoding' =>
array (size=1)
...
'content-length' =>
array (size=1)
...
'connection' =>
array (size=1)
...
'x-php-ob-level' =>
array (size=1)
...
protected 'cacheControl' =>
array (size=1)
'no-cache' => boolean true
protected 'content' => null
protected 'languages' => null
protected 'charsets' => null
protected 'encodings' => null
protected 'acceptableContentTypes' => null
protected 'pathInfo' => string '/posts' (length=6)
protected 'requestUri' => string '/app_dev.php/posts' (length=18)
protected 'baseUrl' => string '/app_dev.php' (length=12)
protected 'basePath' => null
protected 'method' => string 'POST' (length=4)
protected 'format' => null
protected 'session' =>
object(Symfony\Component\HttpFoundation\Session\Session)[5070]
protected 'storage' =>
object(Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage)[5071]
protected 'bags' =>
array (size=2)
...
protected 'started' => boolean false
protected 'closed' => boolean false
protected 'saveHandler' =>
object(Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy)[5090]
...
protected 'metadataBag' =>
object(Symfony\Component\HttpFoundation\Session\Storage\MetadataBag)[5065]
...
private 'flashName' => string 'flashes' (length=7)
private 'attributeName' => string 'attributes' (length=10)
protected 'locale' => null
protected 'defaultLocale' => string 'en' (length=2)
private 'isHostValid' => boolean true
private 'isClientIpsValid' => boolean true
private 'isForwardedValid' => boolean true
The actual field that would be rendered by your form is named get_post[phrase], not just phrase. Submitting get_post[phrase] in postman will work.
If you don't want that naming scheme you can override the getBlockPrefix method in your Form, eg:
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class GetPostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('phrase', TextType::class);
}
public function getBlockPrefix()
{
return null;
}
}

zendframework standard URL parameters

i have problems with the zend framework 1, i use a paywall api and it use a pingback url methode, for example:
myurl.com/payback?user_id=123&foo=bar...
But the problem is now i can't read the params in zendframework.
It work only if i do it like that
myurl.com/payback/user_id/123/foo/bar
i used different methodes to read it out:
$q = $this->getRequest()->getQuery();
$p = $this->getRequest()->getParams();
the request object look like that:
object(Zend_Controller_Request_Http)[74]
protected '_paramSources' =>
array (size=2)
0 => string '_GET' (length=4)
1 => string '_POST' (length=5)
protected '_requestUri' => string '/index/paywall?uid=zIhvpyVslUS5ND79AfMeBPao1LjXY2Kc&goodsid=6001&slength=&speriod=&type=0&ref=&is_test=1&sig=c62538caf7a36ea2f3a795bb3dc32c07' (length=141)
protected '_baseUrl' => string '' (length=0)
protected '_basePath' => null
protected '_pathInfo' => string '/index/paywall' (length=14)
protected '_params' =>
array (size=3)
'controller' => string 'index' (length=5)
'action' => string 'paywall' (length=7)
'module' => string 'default' (length=7)
protected '_rawBody' => null
protected '_aliases' =>
array (size=0)
empty
protected '_dispatched' => boolean true
protected '_module' => string 'default' (length=7)
protected '_moduleKey' => string 'module' (length=6)
protected '_controller' => string 'index' (length=5)
protected '_controllerKey' => string 'controller' (length=10)
protected '_action' => string 'paywall' (length=7)
protected '_actionKey' => string 'action' (length=6)
I Hope someone can help me,
thank you

Google Spreadsheets Get Cell Comments/Notes

I'm having a nasty time learning how to use the gdata api and zend framework.
I've basically got a spreadsheet that I want the data from.
I've managed to get it into an array that I'm happy with using the following code (most likely over bloated)
<?php
/* Load the Zend Gdata classes. */
function number_ending($number){
$suff = array("","st","nd","rd","th");
$index = intval($number);
if($index > 4){
$index = 4;
}elseif($index < 1){
$index = 0;
}
return ($number . $suff[$index]);
}
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_Gbase');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$username = "XXXXXXXXXXXXXXX";
$password = "XXXXXXXXX";
$key = "XXXXXXXXXXXX";
//---------------------------------------------------------------------------------
// Init Zend Gdata service
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service);
$spreadSheetService = new Zend_Gdata_Spreadsheets($client);
//--------------------------------------------------------------------------------
// Example 1: Get cell data
$query = new Zend_Gdata_Spreadsheets_DocumentQuery();
$query->setSpreadsheetKey($key);
$feed = $spreadSheetService->getWorksheetFeed($query);
$entries = $feed->entries[0]->getContentsAsRows();
var_dump($entries);
exit;
//sort the headings out
$headingRow = array_slice($entries[0], 1, 6);
$headings = array();
reset($headingRow);
$month = key($headingRow);
foreach ($headingRow as $key => $value) {
$headings[] = number_ending($value);
}
//sort the content
unset($entries[0]);
$people = array();
foreach($entries as $k => $person){
$person = array_slice($person, 0, 6);
$formatted = array();
foreach ($person as $key => $value) {
$formatted[] = $value;
}
$people[$formatted[0]] = $formatted;
array_shift( $people[$formatted[0]] );
}
foreach ($people as $pkey => $person) {
foreach ($person as $key => $date) {
$people[$pkey][$headings[$key]] = $date;
unset($people[$pkey][$key]);
}
}
However The data that I'm getting back doesn't contain any of the notes/comments assigned to that cell.
All I'm getting returned is
array (size=10)
0 =>
array (size=85)
'_cokwr' => string 'Column A' (length=11)
'may' => string '29' (length=2)
'_e1qt2' => string '30' (length=2)
'_e35dj' => string '1' (length=1)
'_e4jxw' => string '2' (length=1)
'_e5yid' => string '3' (length=1)
'_faot2' => string '4' (length=1)
'may_2' => string '6' (length=1)
'_yhrze' => string '7' (length=1)
'_yj6jv' => string '8' (length=1)
'_ykl48' => string '9' (length=1)
'_ylzop' => string '10' (length=2)
'_yc5pq' => string '11' (length=2)
'may_3' => string '13' (length=2)
'_ygdf1' => string '14' (length=2)
'_yt0iq' => string '15' (length=2)
'_yuf37' => string '16' (length=2)
'_yvtnk' => string '17' (length=2)
'_yx881' => string '18' (length=2)
'may_4' => string '20' (length=2)
'_yq7dw' => string '21' (length=2)
'_yrlyd' => string '22' (length=2)
'_u4gbe' => string '23' (length=2)
'_u5uvv' => string '24' (length=2)
'_u79g8' => string '25' (length=2)
'may_5' => string '27' (length=2)
'_u08m7' => string '28' (length=2)
'_u1n6k' => string '29' (length=2)
'_u31r1' => string '30' (length=2)
'_ufouq' => string '31' (length=2)
'_uh3f7' => string '1' (length=1)
'june' => string '3' (length=1)
'_ua2l2' => string '4' (length=1)
'_ubh5j' => string '5' (length=1)
'_ucvpw' => string '6' (length=1)
'_ueaad' => string '7' (length=1)
'_uqxe2' => string '8' (length=1)
'june_2' => string '10' (length=2)
'_uv53d' => string '11' (length=2)
'_ulb4e' => string '12' (length=2)
'_umpov' => string '13' (length=2)
'_uo498' => string '14' (length=2)
'_upitp' => string '15' (length=2)
'june_3' => string '17' (length=2)
'_v4z28' => string '18' (length=2)
'_v6dmp' => string '19' (length=2)
'_uwjnq' => string '20' (length=2)
'_uxy87' => string '21' (length=2)
'_uzcsk' => string '22' (length=2)
'june_4' => string '24' (length=2)
'_vet2z' => string '25' (length=2)
'_vg7nc' => string '26' (length=2)
'_vhm7t' => string '27' (length=2)
'_v7s8u' => string '28' (length=2)
'_v96tb' => string '29' (length=2)
'july' => string '1' (length=1)
'_von1u' => string '2' (length=1)
'_vq1mb' => string '3' (length=1)
'_vrg6o' => string '4' (length=1)
'_vsur5' => string '5' (length=1)
'_vj0s6' => string '6' (length=1)
'july_2' => string '8' (length=1)
'_vn8hh' => string '9' (length=1)
'_vzvl6' => string '10' (length=2)
'_w1a5n' => string '11' (length=2)
'_w2oq0' => string '12' (length=2)
'_w43ah' => string '13' (length=2)
'july_3' => string '15' (length=2)
'_vx2gc' => string '16' (length=2)
'_vyh0t' => string '17' (length=2)
'_wb44i' => string '18' (length=2)
'_wcioz' => string '19' (length=2)
'_wdx9c' => string '20' (length=2)
'july_4' => string '22' (length=2)
'_w6wfb' => string '23' (length=2)
'_w8azo' => string '24' (length=2)
'_w9pk5' => string '25' (length=2)
'_11m5ay' => string '26' (length=2)
'_11njvf' => string '27' (length=2)
'julaugust' => string '29' (length=2)
'_11gj1a' => string '30' (length=2)
'_11hxlr' => string '31' (length=2)
'_11jc64' => string '1' (length=1)
'_11kqql' => string '2' (length=1)
'_11xdua' => string '3' (length=1)
}
I was wondering how I'm supposed to go about that to get it out as well?
Thanks
Use google-apps-script: Create a web app and pull the values via google apps script into your code. --- I suspect this is the only option. I would love to be proved wrong.
As far as I know, gdata style api does not support getting comments, fonts, color etc. But you can grab style data by getting the sheet as HTML. Bit messy, but works fine.

Zend DB query() - how do I perform a database update?

The last line of this code seems to return an object but does not perform the database query. What do I change to get this to actually perform the database update?
$sql = "UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'";
$bind = array($addresses,$status,$id);
$res = $this->getAdapter()->query($sql,$bind);
Here is a var dump of the object in $res:
object(Zend_Db_Statement_Pdo)[102]
protected '_fetchMode' => int 2
protected '_stmt' =>
object(PDOStatement)[100]
public 'queryString' => string 'UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'' (length=80)
protected '_adapter' =>
object(Zend_Db_Adapter_Pdo_Mysql)[43]
protected '_pdoType' => string 'mysql' (length=5)
protected '_numericDataTypes' =>
array
0 => int 0
1 => int 1
2 => int 2
'INT' => int 0
'INTEGER' => int 0
'MEDIUMINT' => int 0
'SMALLINT' => int 0
'TINYINT' => int 0
'BIGINT' => int 1
'SERIAL' => int 1
'DEC' => int 2
'DECIMAL' => int 2
'DOUBLE' => int 2
'DOUBLE PRECISION' => int 2
'FIXED' => int 2
'FLOAT' => int 2
protected '_defaultStmtClass' => string 'Zend_Db_Statement_Pdo' (length=21)
protected '_config' =>
array
'host' => string 'localhost' (length=9)
'username' => string 'root' (length=4)
'password' => string '' (length=0)
'dbname' => string 'vi' (length=2)
'charset' => null
'persistent' => boolean false
'options' =>
array
...
'driver_options' =>
array
...
protected '_fetchMode' => int 2
protected '_profiler' =>
object(Zend_Db_Profiler)[44]
protected '_queryProfiles' =>
array
...
protected '_enabled' => boolean false
protected '_filterElapsedSecs' => null
protected '_filterTypes' => null
protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
protected '_connection' =>
object(PDO)[85]
protected '_caseFolding' => int 0
protected '_autoQuoteIdentifiers' => boolean true
protected '_allowSerialization' => boolean true
protected '_autoReconnectOnUnserialize' => boolean false
protected '_attribute' =>
array
empty
protected '_bindColumn' =>
array
empty
protected '_bindParam' =>
array
empty
protected '_sqlSplit' =>
array
0 => string 'UPDATE vi_admin_email SET processed_send_list = , status = WHERE id = ' (length=71)
protected '_sqlParam' =>
array
0 => string 'UPDATE vi_admin_email SET processed_send_list = , status = WHERE id = ' (length=71)
protected '_queryId' => null
To update an entry in Zend Framework you do as follow :
$data = array(
'processed_send_list' => $addresses,
'status' => $status
);
$dbAdapter = $this->getAdapter();
$where = $dbApdapter->quoteInto('id = ?', $id);
$this->update($data, $where);
With Zend_Db_Table, the data to be updated is specfied in an associative array as the first parameter. The data provided will be escaped when the query is executed. You also have to include a where statement as a string, like id = 1 as the second parameter. In the above example, the quoteInto is optionnal as you can write the where manually, but the value will not be escaped if you do it manually.
I thought I read "query" but you asked about "update".
So the statement would be:
$res->execute().
Forget what I wrote before.
Try this single line of code,
$res = $this->getAdapter()->query("UPDATE vi_admin_email SET processed_send_list = '$addresses', status = '$status' WHERE id = '$id'");

Storing an instance of Zend_Log in Zend_Cache/Zend_Registry with/without custom helper

I am trying to store an instance of Zend_Log (with Zend_Log_Writer_Stream) to Zend_Cache(preferably) or Zend_Registry(fallback) but with the custom helper as an abstraction layer instead of direct access.
Problem
Except when using Zend_Registry directly, everytime Zend_Log_Writer_Stream's _stream property disappears.
I have attached my code below along with the output it generates.
I am not following these links because I have another writer Zend_Log_Writer_Database that writes to a separate database than application so i need to initialize that. For now i have commented it out.
Bootstrap.php - clipped
protected function _initLog() {
// instantiate CacheOrRegistry variable.
$this->_cor = Helper_SCacheOrRegistry::getInstance();
// make sure its not already cached and config for this resource exists.
if ($this->_cor->exists('logger') || !($config = $this->_config->resources->log))
return;
$logger = new Zend_Log();
$config = $config->toArray();
/*
if (isset($config['db']) && is_array($config['db'])) {
$dbParams = $config['db'];
$writerDb = new Zend_Log_Writer_Db(
$this->_cor->get('logDb'),
$dbParams['writerParams']['table'],
$dbParams['writerParams']['columnMapping']);
if (isset($dbParams['filterName'])) {
switch ($dbParams['filterName']) {
case 'Priority':
$writerDb->addFilter(new Zend_Log_Filter_Priority($dbParams['filterParams']['priority']));
break;
}
}
$logger->addWriter($writerDb);
}
*/
if( 'development' === APPLICATION_ENV) {
$fileParams = $this->_options['resources']['log']['file'];
if(!isset($fileParams) || !(is_array($fileParams)))
return;
$writerFile = new Zend_Log_Writer_Stream($fileParams['writerParams']['path'],$fileParams['writerParams']['mode']);
$writerFile->setFormatter(new Zend_Log_Formatter_Simple($fileParams['writerParams']['format']));
if (isset($fileParams['filterName'])) {
switch ($fileParams['filterName']) {
case 'Priority':
$writerFile->addFilter(new Zend_Log_Filter_Priority($fileParams['filterParams']['priority']));
break;
}
}
$logger->addWriter($writerFile);
}
$logger->setEventItem('user_agent', $_SERVER['HTTP_USER_AGENT']);
$logger->setEventItem('get_vars', serialize($_GET));
$logger->setEventItem('post_vars', serialize($_POST));
$logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
$logger->setEventItem('username', $this->_username);
// This has issue of missing _stream, Using Custom Helper with Registry use force.
$this->_cor->set('logger', $logger, true);
$loggerRC = $this->_cor->get('logger', true);
// This also has issue of missing _stream, Using Custom Helper with apc Cache
$this->_cor->set('logger', $logger);
$loggerCC = $this->_cor->get('logger');
// This works perfectly.
Zend_Registry::set($this->_cor->createCacheId('loggerR'), $logger);
$loggerZ = Zend_Registry::get($this->_cor->createCacheId('loggerR'));
// This also seems to have issue of missing _stream, Using apc Cache directly
$cache = Zend_Registry::get('apcCache');
$cache->save($logger, $this->_cor->createCacheId('loggerC'));
$loggerC = $cache->load($this->_cor->createCacheId('loggerC'));
echo "<h3>Logger, local variable</h3>";
var_dump($logger);
echo "<h3>Logger, from Registry using custom helper</h3>";
var_dump($loggerRC);
echo "<h3>Logger, from apc cache using custom helper</h3>";
var_dump($loggerCC);
echo "<h3>Logger, from Zend_Registry, direct.</h3>";
var_dump($loggerZ);
echo "<h3>Logger, from apc Cache, Direct.</h3>";
var_dump($loggerC);
exit;
}
Helper_SCacheOrRegistry.php
class Helper_SCacheOrRegistry {
private $_source;
private static $_instance;
private $_functionsArray = array('Cache' => array(
'get' => '_getFromCache',
'set' => '_saveInCache',
'del' => '_deleteFromCache',
'exists' => '_existsInCache'),
'Registry' => array(
'get' => '_getFromRegistry',
'set' => '_saveInRegistry',
'del' => '_deleteFromRegistry',
'exists' => '_existsInRegistry',
)
);
public static function getInstance() {
if (!isset(self::$_instance)) {
$c = __CLASS__;
self::$_instance = new $c();
}
return self::$_instance;
}
private function _getSource($forceRegistry = null) {
if(true === $forceRegistry)
return Zend_Registry::getInstance();
if (Zend_Registry::getInstance()->offsetExists('apcCache'))
return Zend_Registry::get('apcCache');
else
return Zend_Registry::getInstance();
}
private function _isSourceCache() {
return (!$this->_source instanceof Zend_Registry);
}
public function createCacheId($id) {
return md5(',e#Q!u$#~\|3Pa^e1%oh&s0*<h(7)o-+h/t.' . $id);
}
public function set($key, $value, $forceRegistry = null) {
$this->_fire('set', $this->createCacheId($key), $value, $forceRegistry);
}
public function get($key, $forceRegistry = null) {
return $this->_fire('get', $this->createCacheId($key), null, $forceRegistry);
}
public function del($key, $forceRegistry = null) {
return $this->_fire('del', $this->createCacheId($key), null, $forceRegistry);
}
public function exists($key, $forceRegistry = null) {
return $this->_fire('exists', $this->createCacheId($key), null, $forceRegistry);
}
private function _fire($method, $key, $value = null, $forceRegistry = null) {
$this->_source = $this->_getSource($forceRegistry);
$call = ($this->_isSourceCache()) ?
$this->_functionsArray['Cache'][$method] : $this->_functionsArray['Registry'][$method];
return (isset($value)) ? $this->$call($key, $value) : $this->$call($key);
}
private function _getFromCache($key) {
return $this->_existsInCache($key);
}
private function _saveInCache($key, $value) {
if ($this->_existsInCache($key))
return false;
$this->_source->save($value, $key);
return true;
}
private function _deleteFromCache($key) {
if (!$this->_existsInCache($key))
return false;
$this->_source->remove($key);
return true;
}
private function _existsInCache($key) {
return $this->_source->load($key);
}
private function _getFromRegistry($key) {
if ($this->_existsInRegistry($key))
return unserialize($this->_source->get($key));
return false;
}
private function _saveInRegistry($key, $value) {
if ($this->_existsInRegistry($key))
return false;
$this->_source->set($key, serialize($value));
return true;
}
private function _deleteFromRegistry($key) {
if (!$this->_existsInCache($key))
return false;
$this->_source->offsetUnset($key);
return true;
}
private function _existsInRegistry($key) {
return $this->_source->isRegistered($key);
}
}
Output:
Logger, local variable
object(Zend_Log)[84]
protected '_priorities' =>
array
0 => string 'EMERG' (length=5)
1 => string 'ALERT' (length=5)
2 => string 'CRIT' (length=4)
3 => string 'ERR' (length=3)
4 => string 'WARN' (length=4)
5 => string 'NOTICE' (length=6)
6 => string 'INFO' (length=4)
7 => string 'DEBUG' (length=5)
protected '_writers' =>
array
0 =>
object(Zend_Log_Writer_Stream)[93]
protected '_stream' => resource(77, stream)
protected '_filters' =>
array
0 =>
object(Zend_Log_Filter_Priority)[94]
protected '_priority' => int 7
protected '_operator' => string '<=' (length=2)
protected '_formatter' =>
object(Zend_Log_Formatter_Simple)[95]
protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
[ %priorityName% : %message% ]
[ POST: %post_vars% ]
[ GET: %get_vars% ]
' (length=161)
protected '_filters' =>
array
empty
protected '_extras' =>
array
'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
'get_vars' => string 'a:0:{}' (length=6)
'post_vars' => string 'a:0:{}' (length=6)
'ip' => string '127.0.0.1' (length=9)
'username' => string 'guest' (length=5)
protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
protected '_origErrorHandler' => null
protected '_registeredErrorHandler' => boolean false
protected '_errorHandlerMap' => boolean false
protected '_timestampFormat' => string 'c' (length=1)
Logger, from Registry using custom helper
object(Zend_Log)[96]
protected '_priorities' =>
array
0 => string 'EMERG' (length=5)
1 => string 'ALERT' (length=5)
2 => string 'CRIT' (length=4)
3 => string 'ERR' (length=3)
4 => string 'WARN' (length=4)
5 => string 'NOTICE' (length=6)
6 => string 'INFO' (length=4)
7 => string 'DEBUG' (length=5)
protected '_writers' =>
array
0 =>
object(Zend_Log_Writer_Stream)[97]
protected '_stream' => int 0
protected '_filters' =>
array
0 =>
object(Zend_Log_Filter_Priority)[98]
protected '_priority' => int 7
protected '_operator' => string '<=' (length=2)
protected '_formatter' =>
object(Zend_Log_Formatter_Simple)[99]
protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
[ %priorityName% : %message% ]
[ POST: %post_vars% ]
[ GET: %get_vars% ]
' (length=161)
protected '_filters' =>
array
empty
protected '_extras' =>
array
'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
'get_vars' => string 'a:0:{}' (length=6)
'post_vars' => string 'a:0:{}' (length=6)
'ip' => string '127.0.0.1' (length=9)
'username' => string 'guest' (length=5)
protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
protected '_origErrorHandler' => null
protected '_registeredErrorHandler' => boolean false
protected '_errorHandlerMap' => boolean false
protected '_timestampFormat' => string 'c' (length=1)
Logger, from apc cache using custom helper
object(Zend_Log)[100]
protected '_priorities' =>
array
0 => string 'EMERG' (length=5)
1 => string 'ALERT' (length=5)
2 => string 'CRIT' (length=4)
3 => string 'ERR' (length=3)
4 => string 'WARN' (length=4)
5 => string 'NOTICE' (length=6)
6 => string 'INFO' (length=4)
7 => string 'DEBUG' (length=5)
protected '_writers' =>
array
0 =>
object(Zend_Log_Writer_Stream)[101]
protected '_stream' => int 0
protected '_filters' =>
array
0 =>
object(Zend_Log_Filter_Priority)[102]
protected '_priority' => int 7
protected '_operator' => string '<=' (length=2)
protected '_formatter' =>
object(Zend_Log_Formatter_Simple)[103]
protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
[ %priorityName% : %message% ]
[ POST: %post_vars% ]
[ GET: %get_vars% ]
' (length=161)
protected '_filters' =>
array
empty
protected '_extras' =>
array
'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
'get_vars' => string 'a:0:{}' (length=6)
'post_vars' => string 'a:0:{}' (length=6)
'ip' => string '127.0.0.1' (length=9)
'username' => string 'guest' (length=5)
protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
protected '_origErrorHandler' => null
protected '_registeredErrorHandler' => boolean false
protected '_errorHandlerMap' => boolean false
protected '_timestampFormat' => string 'c' (length=1)
Logger, from Zend_Registry, direct.
object(Zend_Log)[84]
protected '_priorities' =>
array
0 => string 'EMERG' (length=5)
1 => string 'ALERT' (length=5)
2 => string 'CRIT' (length=4)
3 => string 'ERR' (length=3)
4 => string 'WARN' (length=4)
5 => string 'NOTICE' (length=6)
6 => string 'INFO' (length=4)
7 => string 'DEBUG' (length=5)
protected '_writers' =>
array
0 =>
object(Zend_Log_Writer_Stream)[93]
protected '_stream' => resource(77, stream)
protected '_filters' =>
array
0 =>
object(Zend_Log_Filter_Priority)[94]
protected '_priority' => int 7
protected '_operator' => string '<=' (length=2)
protected '_formatter' =>
object(Zend_Log_Formatter_Simple)[95]
protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
[ %priorityName% : %message% ]
[ POST: %post_vars% ]
[ GET: %get_vars% ]
' (length=161)
protected '_filters' =>
array
empty
protected '_extras' =>
array
'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
'get_vars' => string 'a:0:{}' (length=6)
'post_vars' => string 'a:0:{}' (length=6)
'ip' => string '127.0.0.1' (length=9)
'username' => string 'guest' (length=5)
protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
protected '_origErrorHandler' => null
protected '_registeredErrorHandler' => boolean false
protected '_errorHandlerMap' => boolean false
protected '_timestampFormat' => string 'c' (length=1)
Logger, from apc Cache, Direct.
object(Zend_Log)[104]
protected '_priorities' =>
array
0 => string 'EMERG' (length=5)
1 => string 'ALERT' (length=5)
2 => string 'CRIT' (length=4)
3 => string 'ERR' (length=3)
4 => string 'WARN' (length=4)
5 => string 'NOTICE' (length=6)
6 => string 'INFO' (length=4)
7 => string 'DEBUG' (length=5)
protected '_writers' =>
array
0 =>
object(Zend_Log_Writer_Stream)[105]
protected '_stream' => int 0
protected '_filters' =>
array
0 =>
object(Zend_Log_Filter_Priority)[106]
protected '_priority' => int 7
protected '_operator' => string '<=' (length=2)
protected '_formatter' =>
object(Zend_Log_Formatter_Simple)[107]
protected '_format' => string ' [ %ip% ] - [ %timestamp% ] [ %user_agent% ] - [ %username% ]
[ %priorityName% : %message% ]
[ POST: %post_vars% ]
[ GET: %get_vars% ]
' (length=161)
protected '_filters' =>
array
empty
protected '_extras' =>
array
'user_agent' => string 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.18 Safari/535.1' (length=99)
'get_vars' => string 'a:0:{}' (length=6)
'post_vars' => string 'a:0:{}' (length=6)
'ip' => string '127.0.0.1' (length=9)
'username' => string 'guest' (length=5)
protected '_defaultWriterNamespace' => string 'Zend_Log_Writer' (length=15)
protected '_defaultFilterNamespace' => string 'Zend_Log_Filter' (length=15)
protected '_defaultFormatterNamespace' => string 'Zend_Log_Formatter' (length=18)
protected '_origErrorHandler' => null
protected '_registeredErrorHandler' => boolean false
protected '_errorHandlerMap' => boolean false
protected '_timestampFormat' => string 'c' (length=1)
Zend_Log shouldn't be serialized when stored.
Zend_Cache isn't an option because it required objects to be serialized as it stores only strings.
Zend_Registry wasn't working through helper class as there was some serialization going on due to the code. Removing that fixed the issue.
So in short:
Use Zend_Registry to store objects
Do not serialize when storing in Zend_Registry