SoftDeletes Memory issue with php 7.4 and Illuminate 7.9.2 - eloquent

We have a project with eloquent (without Laravel).
Recently we upgrade to php 7.4, and then Iluminate/database to 7.9.2
In seeder, when we insert data into model without SofDelete, it works.
But when model have softdelete, it hangs.
Example Role:
use Illuminate\Database\Eloquent\Model as Eloquent;
class Role extends Eloquent {
protected $table = 'usuarios_roles';
public $timestamps = true;
...
$admin = Role::create(array(
'nombre' => 'Admin',
'vista' => '1',
'path' => '/admin/clientes/',
'editables' => 0
));
Works fine.
Example User:
require_once('EloquentRegAcc.php');
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends EloquentRegAcc
{
use SoftDeletes;
public $timestamps = true;
protected $dates = ['deleted_at'];
protected $table = 'usuarios';
...
$usuario_admin = Usuario::create(array(
'id_role' => $admin2->id,
'nombre' => 'Admin',
'email' => $email,
'password' => $password2,
'permissions' => '{}'
));
It give us an error:
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 20480 bytes) in /home/vagrant/code/project/vendor/illuminate/database/Eloquent/SoftDeletes.php on line 36
We try to upgrade Vagrant RAM, from 2GB to 4GB, and set ini_set('memory_limit', '4096M') , but no way.
In the database we have roles, but not users.
Same code with php 7.1 and Iluminate/database 5.x works fine.
not matter if is user or other table; if model have SoftDelete, hangs.

We have a "homemade" log in the app.
If we change
require_once('EloquentRegAcc.php');
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends EloquentRegAcc
{
To
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
class Usuario extends Eloquent
{
Works as spect. We need to rewrite or log.

Related

Loses the connection name when obtaining a record (Outside Laravel / enssegers/laravel-mongodb)

I need your help, I am using Eloquent and enssegers / laravel-mongodb outside Laravel Framework, I have managed to correctly configure both Eloquent and laravel-mongodb and it works correctly to insert and obtain results, however, when trying to modify a registry, eloquent loses the connection name by throwing the following error:
Argument 1 passed to Jenssegers\Mongodb\Query\Builder::__construct() must be an instance of Jenssegers\Mongodb\Connection, instance of Illuminate\Database\MySqlConnection given, called in /www/html/syberianbox/sachiel/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Eloquent/Model.php on line 421
I share the configuration of Eloquent through Capsula and laravel-mongodb
$this->_capsule = new Capsule();
$this->_capsule->getDatabaseManager()->extend('mongodb', function($config) {
return new MongodbConnect($config);
});
//MySQL connection, $ this -> _ config contains an array with the correct values
$this->addConnection('default', [
'driver' => $this->_config['default']['driver']
,'host' => $this->_config['default']['host']
,'database' => $this->_config['default']['database']
,'username' => $this->_config['default']['username']
,'password' => $this->_config['default']['password']
,'charset' => $this->_config['default']['charset']
,'collation' => $this->_config['default']['collation']
,'prefix' => $this->_config['default']['prefix']
]);
//MongoDB connection
$this->addConnection('archivos', [
'driver' => $this->_config['archivos']['driver']
,'host' => $this->_config['archivos']['host']
,'port' => $this->_config['archivos']['port']
,'database' => $this->_config['archivos']['database']
]);
Model:
<?php
namespace Instances\Generic\Models\CFDI;
use Jenssegers\Mongodb\Eloquent\Model;
class Archivo extends Model
{
protected $collection = 'cfdi';
protected $connection = 'archivos';
}
Execute model:
$archivoDB = Archvio::Where('_id',$id)->first();
$this->_logger->info('Archivo: ', $archivoDB);
$archivoDB->uuid = $uuid;
$archivoDB->type = $type;
$archivoDB->content = $content;
$archivoDB->save();
Logger:
[2019-02-12 14:20:36:511603][Instances/Generic/Modules/Administracion/ArchivosController.php : 75][Info][30117] Archivo:
Instances\Generic\Models\CFDI\Archivo Object
(
[collection:protected] => cfdi
[connection:protected] =>
[primaryKey:protected] => _id
[keyType:protected] => string
.....
I was able to solve the problem, however it is more a patch than a complete solution.
I extend the class Model of jenssegers / laravel-mongodb and on I write the method getConnectionName () and return the name of the expected connection, as in my case it is only a single connection the name remains as static, however, the method gives the arrow to be able to include all the necessary logic to identify the connection with the model in question
Model:
<?php
namespace Syberianbox\Db;
use Jenssegers\Mongodb\Eloquent\Model;
class Monomodel extends Model
{
public function getConnectionName() {
return 'archivos';
}
}

Mailable bug .. laravel 5.3 and 5.4 can't send from user

Laravel Version:5.3
PHP Version: 7.0
Database Driver & Version: MySQL 5.7
Description:
I'm running into this problem when trying to set the sender (not to) and I end up getting an error that looks like this
Symfony\Component\Debug\Exception\FatalThrowableError: [] operator not
supported for strings in
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php:384
even though I'm entering an email string It is conflicting with the system email address that I have setup in mail.php.
Nowhere else in the system do I get errors when trying to set email to send from a different email address. I'm trying to send it from the authorized user email
So, in my mailable class, I'm using
public function build()
{
return $this->from(Auth::user()->email)
} ->view('mailbox.sendmail');
But in my mail.php
'from' => [
'address' => 'no-reply#swellsystem.com',
'name' => 'Swell Systems',
],
What is the solution?
This is my Mailable -- UserEmail class. I'm using it to send queued user emails. I have a few dependencies I'm getting from a $request
<?php
namespace App\Mail;
use Auth;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class UserEmail extends Mailable
{
use Queueable, SerializesModels;
public $from, $subject, $content;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($from, $subject, $content)
{
//
$this->from = $from;
$this->subject = $subject;
$this->content = $content;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->from($this->from)
->view('mailbox.sendmail')
->subject('Subject:' . $this->subject)
->with(['body' => $this->content])
}
I call it from a controller
namespace App\Http\Controllers;
use App\Mail\UserEmail;
use Auth;
use Mail;
$from = Auth::user()->email;
$subject = $request->input( 'subject' );
$content = $request->input( 'content' );
Mail::to($request->to)->later($when, (new UserEmail($from, $subject, $content))->onQueue('emails'));
This is the exception given it throws in more detail
Symfony\Component\Debug\Exception\FatalThrowableError: [] operator not
supported for strings in
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php:384
Stack trace
1 .
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php(312):
Illuminate\Mail\Mailable->setAddress('nmorgan#designl...', NULL,
'from') 2 . C:\wamp\www\enterprise\app\Mail\UserEmail.php(51):
Illuminate\Mail\Mailable->from('nmorgan#designl...')
--[internal function]: App\Mail\UserEmail->build() 3 . C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Container\Container.php(508):
call_user
If I comment out from in the class the email is sent from the system(mail.php). Otherwise, it throws the error
Would it have to do with anything in my setup? Is there something I am missing.
Mail.php
'from' => [
'address' => 'no-reply#example.com',
'name' => 'System',
],
I found this posted 9 months ago on Laravel.io forum but I don't have a message variable.
<https://laravel.io/forum/10-05-2016-mailablephp-line-382-operator-not-supported-for-strings>
I'm positive that $this->from or Auth::user()->email is definitely a string.. I dumped it and it is "emal#user.com" but I removed it all together and put 'name#example.com' and got the same error
fixed it by removing from in app.php and setting from in every mail

After switch to mongoDB auth::attempt does not work anymore

I recently switched my Laravel 4 Project to the mongoDB System using the jenssegers/laravel-mongodb Package.
The Seeds and migrations are fine, but the Auth::attempt function always returns false now. This worked quite nice before.
This is how the attribute looks like in the seeds:
'password' => Hash::make ( 'password' ),
This is how the data is compared by Auth::attempt:
$userdata = array(
'email' =>Input::get('email'),
'password' => Input::get('password'),
);
$loginResult = Auth::attempt($userdata, $post_remember);
I inserted
use Jenssegers\Mongodb\Model as Eloquent;
in all Models, Seeds, Migrations and the controller.
But auth.attempt ALWAYS returns false.
Since you are using Laravel 4 you can fix this by implementing "UserInterface" in your User model.
use Illuminate\Auth\UserInterface;
use Jenssegers\Mongodb\Model as Eloquent;
and then:
class User extends Eloquent implements UserInterface
{
}
For Laravel 5:
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Jenssegers\Mongodb\Model as Eloquent;
class User extends Eloquent implements AuthenticatableContract
{
use Authenticatable;
}

Laravel 4, Ubuntu, SQL Server 2008R2

I'm using default PHP 5.3.10 in my ubuntu box. and install php5-sysbase.
I tested with this code and success connected to my SQL Server
<?php
$link = mssql_connect('125.0.0.1', 'sa', '12345');
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo'Successful connection';
mssql_close($link);
Now I'm following the quickstart tutorial until arrive at database things in http://laravel.com/docs/quick#creating-a-migration
I use default db driver sqlsrv, with this config:
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => '125.0.0.1',
'database' => 'laravel',
'username' => 'sa',
'password' => '12345',
'prefix' => '',
),
When I execute php artisan migrate, I got an error
[Exception]
SQLSTATE[HY000]: General error: 102 General SQL Server error: Check message
s from the SQL Server [102] (severity 15) [(null)] (SQL: create table "migr
ations" ("migration" nvarchar(255) not null, "batch" int not null)) (Bindin
gs: array (
))
What could be the problem? Thanks for any helps
EDIT01:
here's sql message:
message_id language_id severity is_event_logged text
102 1033 15 0 Incorrect syntax near '%.*ls'.
here's my migration file:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Change this:
protected $wrapper = '"%s"';
To this:
protected $wrapper = '[%s]';

Using Zend Framework Db Tables without MVC

I am trying to use the Zend Framework without using the MVC structure, specifically the Db_Table classes.
I have created a couple of classes representing my database tables, i.e.
class DBTables_Templates extends Zend_Db_Table_Abstract
{
protected $_name = "templates";
}
When I try to instantiate this class (it is included fine), I get the following error:
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for DBTables_Templates'
Does anyone know how I create and include the database adapter for the Db_Table classes to use?
Any pointers are greatly appreciated! I am using the latest version of ZF.
You need to create a Zend_Db_Adapter, which is the class you use to connect to the database.
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
Or you can use the factory() method to make instantiation more configurable:
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
See http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting
Then specify this adapter object to your table class. There are at least three ways to do this:
Set an application-wide default for all tables:
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Specify the adapter to the table constructor:
$table = new MyTable( array('db'=>$db) );
Store the adapter in the registry and specify it to the table or set it as default:
Zend_Registry::set('my_db', $db);
$table = new MyTable( array('db'=>'my_db') );
// alternatively:
Zend_Db_Table_Abstract::setDefaultAdapter('my_db');
See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.constructing