Error: One or more parameter values were invalid--DynamoDb - amazon-dynamodb

I am trying to update a table in DynamoDb with the following code..
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"AttributeUpdates" => array(
'PlayerPrice' => array(
'N' => '5'
),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW
));
print_r($response);
However, an error interrupts its execution. It says:
One or more parameter values were invalid: Only DELETE action is allowed
when no attribute value is specified.
Could anybody help me with this issue?

Looks like the for format of the request was missing the 'Action' and 'Value' parameters. E.g. the following is working for me:
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,
"AttributeUpdates" => array(
'PlayerPrice' => array(
'Action' => \Aws\DynamoDb\Enum\AttributeAction::PUT,
'Value' => array('N' => '5'),
)
)
));
print_r($response);
You can also use an UpdateExpression to achieve the same effect (UpdateExpressions also provide greater flexibility than AttributeUpdates so they are generally recommended):
$response = $client->updateItem(array(
"TableName" => "PlayerInfo",
"Key" => array(
"PlayerId" => array('N' => '201503261435580358849074082'),
),
"ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,
"UpdateExpression" => "SET #pp = :val",
"ExpressionAttributeNames" => array(
"#pp" => "PlayerPrice",
),
"ExpressionAttributeValues" => array(
':val' => array('N' => '5')
)
));
print_r($response);

Related

Having trouble with Symfony2 uploading file from external program - 'mimeType' => 'application/octet-stream'

I have a Symfony2 endpoint that needs to accept a post request with a few text parameters and a zip file delivered by a 3rd party program. For quick development I started out by just using a Chrome POST plugin to spoof sending the form data. I was able to retrieve the file just fine when using that method.
However, when I switched to the 3rd party Windows application for uploading reports, I'm no longer able to retrieve the file. Instead of figuring out that it's a zip file, I now get mimeType' => 'application/octet-stream', and the file size is 0.
I read here in the following link that I needed to make sure my post_max_size and upload_max_filesize were large enough to handle the file. Can't upload image with mime-type "application/octet-stream" in Symfony2
I didn't want to mess around, so I set it to 100mb, but still no luck.
Here is a dump of the Request:
[2016-08-24 10:15:48] app.INFO: Request dump: Symfony\Component\HttpFoundation\Request::__set_state(array( 'attributes' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( '_format' => 'xml', '_controller' => 'Company\\Bundle\\CompanyBundle\\Controller\\DefaultController::cloudTransferReport', '_route' => 'hg_cloudtransfer_report', '_route_params' => array ( '_format' => 'xml', ), '_method' => Sensio\Bundle\FrameworkExtraBundle\Configuration\Method::__set_state(array( 'methods' => array ( 0 => 'POST', 1 => 'GET', ), )), ), )), 'request' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( 'submitter' => 'hgis', 'version' => '5.1.26.0', 'userName' => 'admin', 'password' => 'kitten', ), )), 'query' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( ), )), 'server' => Symfony\Component\HttpFoundation\ServerBag::__set_state(array( 'parameters' => array ( 'REDIRECT_HTTPS' => 'on', 'REDIRECT_SSL_TLS_SNI' => 'example.com', 'REDIRECT_STATUS' => '200', 'HTTPS' => 'on', 'SSL_TLS_SNI' => 'example.com', 'CONTENT_TYPE' => 'multipart/form-data, boundary=AaBbCcDdHhGg40', 'HTTP_USER_AGENT' => 'Some software v 5.1.26.0', 'HTTP_HOST' => 'example.com', 'CONTENT_LENGTH' => '3592731', 'HTTP_CACHE_CONTROL' => 'no-cache', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.4.18 (Unix) PHP/5.5.36 LibreSSL/2.2.7', 'SERVER_NAME' => 'example.com', 'SERVER_ADDR' => '192.168.1.100', 'SERVER_PORT' => '443', 'REMOTE_ADDR' => '192.168.1.223', 'DOCUMENT_ROOT' => '/Users/user/Documents/symphony/cpsrecall/web', 'REQUEST_SCHEME' => 'https', 'CONTEXT_PREFIX' => '', 'CONTEXT_DOCUMENT_ROOT' => '/Users/user/Documents/symphony/cpsrecall/web', 'SERVER_ADMIN' => 'chris#yourcontactpoint.com', 'SCRIPT_FILENAME' => '/Users/user/Documents/symphony/cpsrecall/web/app.php', 'REMOTE_PORT' => '51248', 'REDIRECT_URL' => '/hg/cloudtransfer/upload-report', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'POST', 'QUERY_STRING' => '', 'REQUEST_URI' => '/hg/cloudtransfer/upload-report', 'SCRIPT_NAME' => '/app.php', 'PHP_SELF' => '/app.php', 'REQUEST_TIME_FLOAT' => 1472055346.6129999, 'REQUEST_TIME' => 1472055346, ), )), 'files' => Symfony\Component\HttpFoundation\FileBag::__set_state(array( 'parameters' => array ( 'file1' => Symfony\Component\HttpFoundation\File\UploadedFile::__set_state(array( 'test' => false, 'originalName' => '00000003-1.zip', 'mimeType' => 'application/octet-stream', 'size' => 0, 'error' => 1, )), ), )), 'cookies' => Symfony\Component\HttpFoundation\ParameterBag::__set_state(array( 'parameters' => array ( ), )), 'headers' => Symfony\Component\HttpFoundation\HeaderBag::__set_state(array( 'headers' => array ( 'content-type' => array ( 0 => 'multipart/form-data, boundary=AaBbCcDdHhGg40', ), 'user-agent' => array ( 0 => 'Some software v 5.1.26.0', ), 'host' => array ( 0 => 'example.com', ), 'content-length' => array ( 0 => '3592731', ), 'cache-control' => array ( 0 => 'no-cache', ), 'x-php-ob-level' => array ( 0 => 1, ), ), 'cacheControl' => array ( 'no-cache' => true, ), )), 'content' => '', 'languages' => NULL, 'charsets' => NULL, 'encodings' => NULL, 'acceptableContentTypes' => NULL, 'pathInfo' => '/hg/cloudtransfer/upload-report', 'requestUri' => '/hg/cloudtransfer/upload-report', 'baseUrl' => '', 'basePath' => NULL, 'method' => 'POST', 'format' => NULL, 'session' => Symfony\Component\HttpFoundation\Session\Session::__set_state(array( 'storage' => Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::__set_state(array( 'bags' => array ( 'attributes' => Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag::__set_state(array( 'name' => 'attributes', 'storageKey' => '_sf2_attributes', 'attributes' => array ( ), )), 'flashes' => Symfony\Component\HttpFoundation\Session\Flash\FlashBag::__set_state(array( 'name' => 'flashes', 'flashes' => array ( ), 'storageKey' => '_sf2_flashes', )), ), 'started' => false, 'closed' => false, 'saveHandler' => Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy::__set_state(array( 'handler' => SessionHandler::__set_state(array( )), 'wrapper' => true, 'active' => false, 'saveHandlerName' => 'files', )), 'metadataBag' => Symfony\Component\HttpFoundation\Session\Storage\MetadataBag::__set_state(array( 'name' => '__metadata', 'storageKey' => '_sf2_meta', 'meta' => array ( 'c' => 0, 'u' => 0, 'l' => 0, ), 'lastUsed' => NULL, 'updateThreshold' => '0', )), )), 'flashName' => 'flashes', 'attributeName' => 'attributes', )), 'locale' => NULL, 'defaultLocale' => 'en', )) [] []
and for those who don't want to read that big long line, here's just the FileBag:
[2016-08-24 10:15:48] app.INFO: file1dump: Symfony\Component\HttpFoundation\File\UploadedFile::__set_state(array( 'test' => false, 'originalName' => '00000003-1.zip', 'mimeType' => 'application/octet-stream', 'size' => 0, 'error' => 1, )) [] []
Here is my code up that should grab the file, but perhaps I'm going about it wrong:
public function cloudTransferReport(Request $request)
{
$logger = $this->get('logger');
$em = $this->getDoctrine()->getManager();
$data = $request->request;
$files = $request->files;
$submitter = $data->get('submitter');
$version = $data->get('version');
$memberName = $data->get('userName');
$password = $data->get('password');
$file1 = $files->get('file1');
$logger->info("file string: " . var_export($stuff, true));
$logger->info("file1dump: " . var_export($file1, true));
If you need more code from that controller let me know, but I thought I should at least be able to have the file in memory at this point.
Ok Mac users who run into an issue like this, especially those who have used homebrew, and may or may not have more than one version of PHP installed.
You may have more than one php.ini file on your computer. I ran the php --ini, and it came up with Loaded Configuration File: /usr/local/etc/php/5.6/php.ini. IT WAS WRONG!
Ends up the real php.ini file that Apache was using was in /etc/php.ini, so please, please, please don't waste a whole day banging your head against the keyboard. Make sure you're in the file that Apache is actually using! That is all. I'm going to crawl under my desk and cry now.

cakephp authenticate basic only valid users

I am using the Auth with authenticate Basic.
Is there a way to check if the user is active = 1?
I would like to check that for the Form and the Basic method.
The Basic method is used, when a user log in from an iphone app sending username and password via http header.
public $components = array('Session', 'RequestHandler', 'Auth' => array(
'loginAction' => array(
'controller' => 'api',
'action' => 'login'
),
'authenticate' => array(
'Basic' => array(
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
)
),
'Form' => array(
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
)
)
)
));
Use the scope setting of the AuthComponent and set it using the ALL constant:
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'api',
'action' => 'login'
),
'authenticate' => array(
AuthComponent::ALL => array( // Use this to apply common settings
'userModel' => 'Appuser',
'fields' => array(
'username' => 'name'
),
'scope' => array(
'Appuser.active' => 1 // This is the check you need
)
),
'Basic',
'Form'
)
)
);
For more info, refer to this section in the book.

Adding a value to a textbox generated on Symfony 2

Having this:
echo $view['form'] -> row($form["codelist"], array(
//widget
"widgetArgs" => array(
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist"
),
"tooltip"=>"gift.tooltip.codelist",
"translation_domain" =>"brand"
),
"labelArgs" => array(
"label_attr" => array(
'class' => 'control-label',
)) ,"rowType"=>2
)
);
How do you add an initial value to that textbox?
If you want to add an actual value to the field, you can use the value attribute:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'value' => "Your initial value"
)
But if you are using HTML5 and just want to give a hint to your users, you'd better use a placeholder:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'placeholder' => "Your initial value"
)
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute

View fields from the same database column

So, I have serialized data within the uc_orders table. This data has several parameters of interest each of which I want to create a unique field from.
Each one of these $data values work on their own. Obviously I am rewriting the value on the second declaration. How can I reference the same data location twice so that both of the fields can be used and I can explode all of my serialized data into separate fields?
function uc_order_views_data() {
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order by.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
}
I finally found the answer.
$data['uc_orders']['data2'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'real field' => 'data',
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
The solution is to add 'real field' => 'field name', and change the $data id.

drupal 7. how to refactor a form array

I am creating a wizard from the Drupal example file and would like to refactor the segments of code that are repeated when setting up items like options and radios.
I have already tried a simple function passing "ordinary" and "preferential" but can't find a way to make it work.
Can someone give me an idea of the best way to do this?
unfactored code is as below:
function services_wizard_share_capital_classes($form, &$form_state) {
$form['share_classes']['type_of_class'] = array(
'#type' => 'select',
'#title' => t('What type of share will this class be?'),
'#options' => array(
1 => t('Ordinary'),
2 => t('Preferential'),
),
);
$form['ordinary']['share_type'] = array(
'#type' => 'item',
'#description' => t("You chose Ordinary Shares"),
'#states' => array(
'visible' => array(
':input[name="type_of_class"]' => array('value' => '1'),
),
),
);
$form['preferential']['share_type'] = array(
'#type' => 'item',
'#description' => t("You chose Preferential Shares"),
'#states' => array(
'visible' => array(
':input[name="type_of_class"]' => array('value' => '2'),
),
),
);
return $form;
}
I'm not sure about this being the best way but it's certainly a way to refactor your code:
function _services_wizard_share_capital_classes_add_el(&$form, $name, $description, $index) {
$form[$name]['share_type'] = array(
'#type' => 'item',
'#description' => t($description),
'#states' => array(
'visible' => array(
':input[name="type_of_class"]' => array('value' => "$index"),
),
)
);
}
function services_wizard_share_capital_classes($form, &$form_state) {
// Other code
_services_wizard_share_capital_classes_add_el($form, 'ordinary', 'You chose Ordinary Shares', 1);
_services_wizard_share_capital_classes_add_el($form, 'preferential', 'You chose Preferential Shares', 2);
// etc...
}

Resources