ubercart uc_cart_add_item segment fault 11 - drupal-7

http://api.drupalize.me/api/drupal/function/uc_cart_add_item/7
when i use the function uc_cart_add_item in my module i got segmentfault 11, but when i use this function in page with php-filter it does not have any problem. any clue please..
$regular_count = 2;
if($regular_count > 1) {
if($discount_exist == FALSE) {
$data = array("module" => "uc_product");
$nid = 304;
$qty = 1;
uc_cart_add_item($nid, $qty, $data , NULL, TRUE, TRUE, TRUE);
}
}
When i use this in create-page with php-filter enabled it is working perfectly just for me to test;
But when i use it in my own module i got segmentfault 11 thats the only error.
Do i missed something? like module_load_include, or require_once?
Thank you.

Related

Strict standards issue with Drupal 7 custom module

The following error message is displayed when I visit the homepage:
Strict Standards: Only variables should be passed by reference in C:\wamp\www\vb-15-05-2018-2\sites\all\modules\vb_ymlp\vb_ymlp.module on line 40
This is coming from a custom module and the line within the if statement is the issue. Does this point to a bigger issue or is there a simple solution?
function vb_ymlp_block_view($delta = ""){
module_load_include('inc', 'vb_ymlp', 'vb_ymlp.form');
$block = array();
if($delta == 'vb_ymlp_block'){
// the line below is causing this error
$block['content'] = drupal_render(drupal_get_form('vb_ymlp_form'));
}
return $block;
}
You are not able to set value as function as you set drupal_render()
You have to get it first and then set it to the content variable
Like you have to do
function vb_ymlp_block_view($delta = ""){
module_load_include('inc', 'vb_ymlp', 'vb_ymlp.form');
$block = array();
if($delta == 'vb_ymlp_block'){
// the line below is causing this error
$content = drupal_get_form('vb_ymlp_form');
$content = drupal_render($content);
$block['content'] = $content;
}
return $block;
}
HOPE THIS SOLVE YOUR PROBLEM
THANKS

Joomla Component error - Fatal error

I have installed a ticket module on my Joomla website, I get the following error when a ticket is submitted
Fatal error: Call to undefined method JRegistry::getValue() in /home/xboxfifa/public_html/HD/components/com_jtaghelpdesk/controller.php on line 300
function mailme($formData){
$version = new JVersion();
$body = "A new inquiry has been recieved: <br /> Name : ". $formData['inqName']. "<br /> Email ID : ". $formData['inqEmail']. "<br/> Message : ".$formData['inqMessage'] ;
$mailer =& JFactory::getMailer();
$config =& JFactory::getConfig();
if($version->RELEASE==3.0)
{
$recipient = array(
$config->get('mailfrom'),
$config->get('fromname'));
}else
{
$recipient = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' ));
}
$mailer->addRecipient($recipient);
$subject=$formData['inqSubject'];
$mailer->setSubject($subject);
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$send =& $mailer->Send();
if ( $send !==true )
{ $msg = 'Reply not Sent!';
} else
{
$msg = 'Reply Sent Successfully!';
}
}
If anyone could help me I would appreciate it.
JRegistry::getvalue() was removed in Joomla 3.x so make sure you use JRegistry::get() instead.
As for your version compare, you should use this:
if (version_compare(JVERSION, '3.0.0', 'ge')){
// code here
}
Editing this answer because I realized the issue is something else. The problem here is the $version check you're doing looks for the release to be EXACTLY == 3.0. When really you want that get() method to be used for 3.0 and up. You should change your if-statement to:
if($version->RELEASE >= 3.0)
{ ... }
Because you're using 3.2.1 this will use the proper method gets for that version.

How to pass parameter to Laravel DB::transaction()

From the laravel documentation: Database Transaction.
It says that:
DB::transaction(function() {
DB::table('users')->update(array('votes' => 1));
DB::table('posts')->delete();
});
Here, 1 is explicitly entered to update the users...
I tried this using a variable,
$id = 3;
DB::transaction(function() {
DB::table('users')->where('id','=',$id)->get();
});
It throws an error:
Undefined variable: id
I also tried to place to $id as a parameter like this:
$id = 3;
DB::transaction(function($id) {
DB::table('users')->where('id', '=', $id)->get();
});
Still, an error:
Object of class Illuminate\Database\MySqlConnection could not be converted to string
Have I done anything wrong? Please advise. Thanks...
The use keyword is what you need:
$id = 3;
DB::transaction(function($id) use ($id) {
DB::table('users')->where('id', '=', $id)->get();
});
For PHP 7 (untested, edited as requested by the answer below):
$id = 3;
DB::transaction(function() use ($id) {
DB::table('users')->where('id', '=', $id)->get();
});
In PHP 7 the syntax has changed:
$id = 3;
DB::transaction(function () use ($id) {
DB::table('users')->where('id', '=', $id)->get();
});
To answer #CaptainHypertext question of
If you alter $id inside the closure, will it affect the $id outside?
This method worked for me:
$id = 3;
$transactionResult = DB::transaction(function($id) use ($id) {
$request_id = DB::table('requests')->insertGetId([
'company_id' => $company->$id,
]);
return $request_id ;
});
echo($transactionResult);

Undefined offset: 1 in list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);

So I'm setting up DPS for someone and I've got a little error in my xml_parse. I'm using the sample code from DPS (http://www.paymentexpress.com/Technical_Resources/Sample_code_-_PHP/PX_Post_-_cURL.aspx) and I've modified it to work with PxPay. My problem is it's spitting back an error and I don't know what the code is doing so not sure what's going wrong
This is my code
function parse_xml($data){
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}
}
and I'm getting an "Undefined offset: 1" error on this line
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
as far as I know all it's spitting back to me is something like the following
<Request valid="1">
<URI>https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Samplepxpayuser&request=v5x4Ygc8SJlc3FLYva7pIp6QHqKiSatHN8sNMufz-NNrOGJXn0TJf5TOIVNwQRyNqPo9cPMUfXWJkxjAGGDGDzhkwFD6VxRD2KesUBcmD5ViwVnb4va16zLih9VmKlipvEelGaYsF3fCqudnaWV1abz6f8VNKJOhGeypImjWk9I9xV0-iZh860FPcOam_UVHe81aQ4C2LJKB_znLiWqALSeeOHskI9vxdPOfcsfO7xXOuSMVXsKK6kVX4eZjcODKS1JGKP97fhb4gI2vpR7KUwIGC7U9VkXkPQfAGyYuP1g8x0QR1kC6eNzov3-W48OyvQ1_Fabn8cc1deTrsk6s3bPj3dgrlcXUfnFvmSOemB4rs-ixPDwQcaEsZWQvUcIsaPXAWfQdgtC0dETayY_wVFN8yVmljpCZweiGyNhUHhYGIWLEGuP_Le1HwyHXc_fMaQOeqdZNrFBviCJyWZ2HKferSEwkyQqMmq</URI>
</Request>
Does anyone have any experience with DPS or know what may be going wrong here?
I am getting the result back but it's still spitting me this error in my error reports
EDIT
This is no longer needed. This code is now obsolete
replace eval($php_stmt); with if (isset($xml_elem['value'])) { eval($php_stmt); }

How do I use fixed fields in CakeDC's csvUpload behavior in Util plugin

I am using the csvUpload behavior of the Utils plugin by CakeDC, on a CakePHP 2.2.1 install.
I have it working great it's processing a rather large csv successfully. However there are two fields in my table / Model that would be considered fixed, as they are based on ID's from from associated models that are not consistent. So I need to get these fixed values via variables which is easy enough.
So my question is, how do I use the fixed fields aspect of csvUpload? I have tried that following and many little variation, which obviously didn't work.
public function upload_csv($Id = null) {
$unique_add = 69;
if ( $this->request->is('POST') ) {
$records_count = $this->Model->find( 'count' );
try {
$fixed = array('Model' => array('random_id' => $Id, 'unique_add' => $unique_add));
$this->Model->importCSV($this->request->data['Model']['CsvFile']['tmp_name'], $fixed);
} catch (Exception $e) {
$import_errors = $this->Model->getImportErrors();
$this->set( 'import_errors', $import_errors );
$this->Session->setFlash( __('Error Importing') . ' ' . $this->request->data['Model']['CsvFile']['name'] . ', ' . __('column name mismatch.') );
$this->redirect( array('action'=>'import') );
}
$new_records_count = $this->Model->find( 'count' ) - $records_count;
$this->Session->setFlash(__('Successfully imported') . ' ' . $new_records_count . ' records from ' . $this->request->data['Model']['CsvFile']['name'] );
$this->redirect(array('plugin'=>'usermgmt', 'controller'=>'users', 'action'=>'dashboard'));
}
}
Any help would be greatly appreciated as I have only found 1 post concerning this behavior when I searching...
I made my custom method to achieve the same task. Define the following method in app\Plugin\Utils\Model\Behavior
public function getCSVData(Model &$Model, $file, $fixed = array())
{
$settings = array(
'delimiter' => ',',
'enclosure' => '"',
'hasHeader' => true
);
$this->setup($Model, $settings);
$handle = new SplFileObject($file, 'rb');
$header = $this->_getHeader($Model, $handle);
$db = $Model->getDataSource();
$db->begin($Model);
$saved = array();
$data = array();
$i = 0;
while (($row = $this->_getCSVLine($Model, $handle)) !== false)
{
foreach ($header as $k => $col)
{
// get the data field from Model.field
$col = str_replace('.', '-', trim($col));
if (strpos($col, '.') !== false)
{
list($model,$field) = explode('.', $col);
$data[$i][$model][$field] = (isset($row[$k])) ? $row[$k] : '';
}
else
{
$col = str_replace(' ','_', $col);
$data[$i][$Model->alias][$col] = (isset($row[$k])) ? $row[$k] : '';
}
}
$is_valid_row = false;
foreach($data[$i][$Model->alias] as $col => $value )
{
if(!empty($data[$i][$Model->alias][$col]))
{
$is_valid_row = true;
}
}
if($is_valid_row == true)
{
$i++;
$data = Set::merge($data, $fixed);
}
else
{
unset($data[$i]);
}
}
return $data;
}
And you can use it using:
$csv_data = $this->Model->getCSVData($this->request->data['Model']['CsvFile']['tmp_name'], $fixed);
Here $csv_data will contain an array of all of those records from the csv file which are not empty and with the fixed field in each record index.
So as I was telling Arun, I answered my own question and figured it out. I was looking to broad instead of really examining what was in front of me. I started running some debugging and figured it out.
First of all, $unique_add = 69 is seen as an int, duh. In order for it to be added to the csv it need to viewed as a string. So it simply becomes, $unique_add = '69'.
I couldn't enter the value of $Id directly into the fixed array. So I just had to perform a simple find to get the value I needed.
$needed_id = $this->Model->find('first', array(
'condition'=>array('Model.id'=>$Id)
)
);
$random_id = $needed_id['Model']['id'];
Hopefully this won't be needed to help anyone because hopefully no one else will make this silly mistake. But one plus... Now there's actually more than one post on the internet documenting the use of fixed fields in the CakeDC Utils plugin.

Resources