Symfony2 & Doctrine2 PDOException without description - exception

I wanted to use this code, and it break on flush() without any exception message:
1. at PDOStatement ->execute (null)
in ../vendor/doctrine-dbal/lib/Doctrine/DBAL/Statement.php at line 131
2. at Statement ->execute ()
in ../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 237
3. at BasicEntityPersister ->executeInserts ()
in ../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php at line 726
4. at UnitOfWork ->executeInserts (object(ClassMetadata))
in ../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php at line 292
5. at UnitOfWork ->commit ()
in ../vendor/doctrine/lib/Doctrine/ORM/EntityManager.php at line 334
6. at EntityManager ->flush ()
in ../src/Tools/TFIBundle/Model/CSVImport.php at line 136
7. at CSVImport ->addCategory ('fundusz obligacji')
in ../src/Tools/TFIBundle/Model/CSVImport.php at line 114
addCategory() method looks:
public function addCategory( $categoryName )
{
$category = new Category();
$category->setName( $categoryName );
$this->em->persist( $category );
$this->em->flush();
$this->counter['category']++;
return $category;
}
any idea what is wrong? or how to get PDOException message within symfony2 ?

I had the same problem just seconds ago. It got fixed when I went to the production mode and and closed the session. It looks like development mode has problems with sessions when you do things like replacing the entire folder with a lot of changes while session still alive.
Try clearing your session, it may work.

Related

How do I return a union as an Active Record object?

I have these union in my controller :
$expression = new Expression('"News"');
$featuredNews2= news::find()
->alias('ne')
->select(['ne.title', 'ne.content','ne.featuredOrder', 'category'=>$expression])
->innerJoinWith('featuredOrder1');
$expression2 = new Expression('"Event"');
$featuredEvents2 = event::find()
->select(['ev.title', 'ev.content','ev.featuredOrder','category'=>$expression2])
->from('event ev')
->innerJoinWith('featuredOrder2');
$union = $featuredNews2->union($featuredEvents2);
The relation in model :
news model
public function getFeaturedOrder1()
{
return $this->hasOne(Featured::className(), ['featuredOrder' => 'featuredOrder']);
}
event model
public function getFeaturedOrder2()
{
return $this->hasOne(Featured::className(), ['featuredOrder' => 'featuredOrder']);
}
I need to return the query as an Active Query because I need to access my model's method e.g : $model->featuredOrder1->preview in my view.
The following works but it returns an array, as the result I can't access my model's method :
$unionQuery = (new \yii\db\Query)->select('*')
->from($union)
->orderBy('featuredOrder')->all(\Yii::$app->db2);
I have two questions :
How to return the equivalent $unionQuery above but as an active query object? I have googled and search on SO but what I found is how to return it as array.
This is out of curiosity, I wonder why I should provide my db connection as argument in my $unionQuery all() method above. If I didn't use an argument that point to db2, it will look for table name inside my db database instead ( db is my parent database, this db2 is my module's database/the correct one). This only happen with a union. My news and event model already have this in getdb() function:
return Yii::$app->get('db2');
update
I've tried this too :
$unionProvider = (new ActiveQuery(Featured::className()))->select('*')
->from(['union' => $featuredEvents2->union($featuredNews2)])
->orderBy('featuredOrder');
With this relation in featured model:
public function getNews()
{
return $this->hasOne(News::className(), ['featuredOrder' => 'featuredOrder']);
}
public function getEvents()
{
return $this->hasOne(Event::className(), ['featuredOrder' => 'featuredOrder']);
}
and in the view, I tried this :
foreach($unionProvider as $key=>$model){
echo $model->news->title;
}
but get this error : Trying to get property of non-object
Update 2
I forgot to add ->all() in my $unionProvider, but after that I got this error instead : PHP Fatal Error – yii\base\ErrorException
Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes)
Might be something wrong with my query? Can't figure it out
You can try using pure SQL. Plus you can test to see if it is returning the correct results and then add it in the statement below.
$customers = Customer::findBySql('SELECT * FROM customer')->all();
Learn more in yii docs

Strange controller error after upgrading from symfony 3.0.9 to 3.1.3

I have a very strange problem with my Symfony application. Everything is working fine on symfony 3.0.9, but when upgrading to 3.1 (currently running 3.1.3) I get the following error with almost all Controllers:
"Controller "Name_of_Controller::name_of_method" requires that you
provide a value for the "$request" argument (because there is no
default value or because there is a non optional argument after this
one)."
Here is an example of a method that causes this error:
/**
* This method handles add faculty
* requests
*
* #param Request $request html request
*
* #return Response html response
*
**/
public function addAction(Request $request)
{
// create a new Faculty
$faculty = new Faculty();
$faculty->setFirstname('Enter First Name');
$faculty->setLastname('Enter Last Name');
$form = $this->createForm(FacultyType::class, $faculty);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$task = $request->get('Submit');
// let see what the user wants
switch ($task) {
case 'Add':
// user wants to add
// we are setting the fullname of the object
$lname = $form->getData()->getLastname();
$fname = $form->getData()->getFirstname();
$faculty->setFullname("$lname, $fname");
$em = $this->getDoctrine()->getManager();
$em->persist($faculty);
$em->flush();
// report success
$this->addFlash('success', "The faculty member $faculty was successfully saved!");
return $this->redirectToRoute('faculty_index');
break;
case 'Cancel':
// report failure
$this->addFlash('failure', "The action was cancelled. No faculty member was saved!");
return $this->redirectToRoute('faculty_index');
}
}
return $this->render(
'faculty/add.html.twig',
[
'form' => $form->createView(),
]
);
}
The xml route for this method is as follows:
<route id="faculty_add" path="/add" methods="GET POST">
<default key="_controller">AppBundle:Faculty:add</default>
</route>
As mentioned above, it only happens on 3.1, the whole app works fine on 3.0.9.
Anybody else seen this? Do I have a structural problem in my code that was unveiled in 3.1 (I am not a professional coder...)
thanks!
Andreas
This is not a definitive answer, but might be helpful for those other hobby coders out there that have a similar problem:
The problem disappears when using php7.0 instead of 7.1. The same is true when running symfony 3.0.x on php 7.1.
It only persists when using both php 7.1 and symfony 3.1.
As I tried both dev and prod environments, emptied the cache repeatedly and could reproduce this both on a Digital Ocean Ubuntu droplet and my MacBook Pro, I can't imagine it is a caching issue.
Not sure whether this is a true bug or there is something in my code that causes this problem.
I'll update this should I find a more definitive cause for the problem.
Edited:
I have finally found the cause of the problem (for me): there was a typo in:
use Symfony\Component\HttpFoundation\Request;
(a lowercase letter instead of an uppercase letter). Strange thing: it had been working for years with all the Symfony/PHP versions (from Sf-2.6 and PHP-5.4) and it became a problem recently with the Sf/PHP versions mentioned below.
PHP namespaces are case-insensitive, but Symfony's resolvers seem to be sometimes case-sensitive...
Previous answer:
It seems that this behavior is due to the "ReflectionType improvements" feature in PHP 7.1: pull request.
The consequences on Symfony have been reported on this issue: github.com/symfony/symfony/issues/19677 (sorry, I can't create more than 2 links with my reputation...).
The feature has been reverted since then: ticket.

Can't catch my mysql errors

I am using codeigniter for my server side in php.
I set my email field UNIQUE on my Users table.
The problem is that whatever I tried I can't catch the error mysql generated when trying to insert a duplicate email.
What i tried inside my model:
function insert($arr) {
$query= $this->CI->db->insert('user', $arr);
if($query){
return $this->CI->db->insert_id();
} else {
$msg = $this->CI-db->_error_message();
return $msg;
}
}
The issues goes that everything is fine until I get a duplicate and I actually get NOTHING inside the $msg. I know debug is on from the database config file.
If your database config 'db_debug' => TRUE, your code will exit with showing the error message and you will not able to reach this line $msg = $this->CI-db->_error_message();.
So to catch the error message you need to set the.
db_debug' => FALSE
At CI-2 your above code will work.See more at this question
But At CI-3 those function is not available and it will produce php undefined method error. CI-3 has a method display_error. You can check it.
My solution: If you want the errors you can get it using this line
$msg = $this->db->conn_id->error_list;
This will give you the error lists as array.But remember you need to set db_debug' => FALSE

CurlException: 28: connect() timed out?

Today I was trying to make application on Facebook using PHPSDK and I saw ocassionaly displayed exception from library saying
CurlException: 28: connect() timed out!
So, to check if it's my code bug I downloaded latest library PHPSDK from github. Then I was trying to run examples/example.php file few times, after that I look into error log and this error was also there (not always, looks like it's kind of random thing).
I was trying to find solution on developer forum without any success, as I notice this kind of problem occur in the past, and none knows why.
Any solutions?
Thanks
Same here, totally random but on large access site the error log file come quickly full :/
Bug Open here : http://developers.facebook.com/bugs/182705755149358
Production server Use the same PHP code as shown in the given exemple : https:// developers.facebook.com/blog/post/534/
2 connections on 6 pass. else :
***`print_r($e->getResult());`***
Give :
Array
(
[error_code] => 28
[error] => Array
(
[message] => connect() timed out!
[type] => CurlException
)
)
Else here are the Options in the Facebook.php
/**
* Default options for curl.
*/
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.1',
);
I've Try this :
Raise ConnectTimeOut => Same Problem.
Change Api-Read.Facebook.Com to Api.Facebook.Com => Same Problem.
Try with there Curl Params : CURLOPT_SSL_VERIFYPEER => false,$opts[CURLOPT_SSL_VERIFYHOST] = 2; But not a SSL Problem for my case.
Try to Connect to FB Api/Graph/Api-read server using telnet and port 443 => Same Problem.
Respond only 2 time on 6...
Still actualizing the Platform Live-Status page of Facebook ... Api response time raising ...
https://developers.facebook.com/live_status

MySQL, Asterisk Dialplans and call forwarding

How do I get Asterisk to forward incoming calls based on matching the incoming call number with a number to forward to? Both numbers are stored in a MySQL database.
Sorry for the long code sample, but more than half of it is debugging code to help you get it set up.
I'm assuming your server already has a modern version of PHP (at /usr/bin/php) with the PDO library, and that you have a database table named fwd_table with columns caller_id and destination.
In /var/lib/asterisk/agi-bin get a copy of the PHP AGI library. Then create a file named something like forward_by_callerid.agi that contains:
#!/usr/bin/php
<?php
ini_set('display_errors','false'); //Supress errors getting sent to the Asterisk process
require('phpagi.php');
$agi = new AGI();
try {
$pdo = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=UTF-8', $db_user, $db_pass);
} catch (PDOException $e) {
$agi->conlog("FAIL: Error connecting to the database! " . $e->getMessage());
die();
}
$find_fwd_by_callerid = $pdo->prepare('SELECT destination FROM fwd_table WHERE caller_id=? ');
$caller_id = $agi->request['agi_callerid'];
if($callerid=="unknown" or $callerid=="private" or $callerid==""){
$agi->conlog("Call came in without caller id, I give up");
exit;
}else{
$agi->conlog("Call came in with caller id number $caller_id.");
}
if($find_fwd_by_callerid->execute(array($caller_id)) === false){
$agi->conlog("Database problem searching for forward destination (find_fwd_by_callerid), croaking");
exit;
}
$found_fwds = $find_fwd_by_callerid->fetchAll();
if(count($found_fwds) > 0){
$destination = $found_contacts[0]['destination'];
$agi->set_variable('FWD_TO', $destination);
$agi->conlog("Caller ID matched, setting FWD_TO variable to ''");
}
?>
Then from the dial plan you can call it like this:
AGI(forward_by_callerid.agi)
And if your database has a match, it will set the variable FWD_TO with goodness. Please edit your question if you need more help getting this integrated into your dial plan.
This article should do the trick. It's about 3 lines of code and some simple queries to add and remove forwarding rules.
The solution I was looking for ended up looking like this:
[default]
exten => _X.,1,Set(ARRAY(${EXTEN}_phone)=${DTC_ICF(phone_number,${EXTEN})})
exten => _X.,n(callphone),Dial(SIP/metaswitch/${${EXTEN}_phone},26)
exten => _X.,n(end),Hangup()