yii-dbmigrations does not have a method named "performTransactional" - php

I have a new problem using the latest version of yii-dbmigration, when I run the migration the console shows the message below and the migration not work.
$ ./protected/yiic migrate
Migrations directory: protected/migrations/
=== Applying: m20110123200901_create_eav_table =================================
ERROR: m20110123200901_create_eav_table does not have a method named "performTransactional".
The code of migration is:
<?php
class m20110123200901_create_eav_table extends CDbMigration {
public function up() {
$t = $this->newTable('eav');
$t->primary_key('id');
$t->integer('section_id');
$t->integer('entry_id');
$t->integer('field_id');
$t->string('attribute');
$t->text('value');
$t->datetime('created_at');
$t->datetime('updated_at');
$this->addTable($t);
}
public function down() {
$this->removeTable('eav');
}
}
Anyone know what happens?
Thanks.
Edited
Hi guys,
I found the problem, but I don't know the solution.
The problem occur on the Yii v1.1.7-dev, when I'm using a another version (like v1.1.5-dev) the migrations works right.
Anyone know how to fix it?
Thanks.

Ok guys, I found the problem and the solution.
I was using the yii-dbmigration extension, and the yii has a implementation of migrations since v1.1.6, so the two versions were conflicting when I was run the migrations.
The solutions is, uninstall the extension and use the new native migration.
A personal opinion about the yii native migration feature and the yii extension db-migration is that the second likes more easy and elegant to work because it has a great oop implementation on up/down method.
Thanks

Related

Yii2 $model->_attributes assignment does not work in new version

I inherited a project that was created with Yii2, ver. 2.0.4, with the task to update said project to a more current version of Yii2 (2.0.15) because of the incompatibility of the older one with PHP 7.2+.
I noticed that there is a lot of use of assigning arrays to a model:
$model->_attributes = $array;
With the new version this results in an exception
'yii\base\UnknownPropertyException' with message 'Setting unknown property: app\models\model::_attributes'
For the time being I created a workaround with the following function:
function customSetAttributes(&$model, $array) {
foreach($model->attributeLabels() as $model_key => $model_label) {
if(!isset($array[$model_key])) continue;
$model->$model_key = $array[$model_key];
}
}
Also, the getter function now has a similar issue.
What I would like to know:
Was this type of assignment never intended in the first place (and I just haven't found the previous developer's code that enables it)? I skimmed over the Yii2 changelog but didn't notice anything related.
Is there a way to "salvage" the previous behaviour so I don't have to replace each occurence with my workaround function?
ActiveRecord::$_attributes was always private and never should be used in this way. I guess that previous developer edited framework core files in vendor directory and make this property protected/public.
You may try to emulate this behavior by creating virtual attribute using getter and setter:
public function get_attributes() {
return $this->getAttributes();
}
public function set_attributes($values) {
$this->setAttributes($values, false);
}
But this will not always work and it is more like an ugly hack to make crappy code work. I strongly suggest to fix code to use setAttributes() instead of _attributes.
Also you should compare yii2 package from vendor directory with source from https://github.com/yiisoft/yii2-framework/releases/tag/2.0.4 - you may find more places where core was edited.

Laravel cannot find a Controller Method (does not exist)

I'm trying to implement a new method in a BoController called "deleteBooking", the method is defined:
public function deleteBooking($id){
$booking = Reservation::find($id);
if($booking && $booking->delete()){
try {
$email = Mail::to($booking->user_email)->send(new Cancel($booking));
} catch(\Exception $e){
Log::error($e->getMessage());
}
return redirect('admin/manager/home')->with('message','Réservation annulée!');
}
return redirect('admin/manager/home')->with('message','Réservation non annulée!');
}
But laravel at the endpoint says:
(1/1) BadMethodCallException
Method [deleteBooking] does not exist.
Other methods from the same class are linked to endpoints too, and work well.
Do you have any ideas please? Thank you.
I got it fixed, I've found another file called BoController, in another folder somehow and it was conflicting with the App\Http\Controllers one.
Thank you.
It's most likely that you have declared that function for some other request type other than the one you're trying to make. For example you put Route::post('some-method', 'BoController#deleteBooking'); but you need to put either Route::get(...) or Route::put(...) or Route::delete(...).
If it isn't that problem, then you probably misspelled it.
I have faced similar issue. Then I have figured out a issue pointed in composer install log, with following instance of log line:
Class App\Http\Controllers\BlogController located in ./app/Http/Controllers/BlogControllerOld.php does not comply with psr-4 autoloading standard. Skipping.
Based on that I have found that one of the file renamed with Old suffix was creating conflict with the main file. So here I have to chhoseone of the following solutions:
To delete the file created for backup.
Or just rename the class in duplicated file to BlogControllerOld.
So its a good idea to check for issues with composer install
It will highlight the conflicts that can be fixed using one of the method above.
Once fixed using specified methods above issue composer install to apply the fix and regenerate autoloader.

laravel 'class not found' error on production

Slightly odd one here.
I have Persons and Actions. Persons can have many Actions, while each Action belongs to only one Person. I'm using Chumper's Datatables to display a list of people, including a count of their actions.
Since migrating to a production (forge) server, I'm getting
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Class 'action' not found
when calling the datatable. The error shown
/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php:721
public function hasOne($related, $foreignKey = null, $localKey = null)
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related;
$localKey = $localKey ?: $this->getKeyName();
suggests it's a problem with my hasMany relationship:
# /models/Person.php
class Person extends Eloquent {
public function actions()
{
return $this->hasMany('Action');
}
# /models/Action.php
class Action extends Eloquent {
public function person()
{
return $this->belongsTo('Person', 'person_id');
}
I assume these are fine, however, as it all works locally. Datatables also works fine elsewhere, calling through other items and their related actions with no trouble.
I've tried composer dump-autoload and artisan dump-autoload on the production server, to no avail. The deployment script on forge is below:
git pull origin master
composer install
php artisan migrate --env=production
I can't tell if it's a config issue, a database issue, a code issue or something else entirely. I've been back through the many similar questions but nothing's jumped out. Any help much appreciated.
for who may have the same problem, triple check the casing of your model! I had it wrong, that's why locally on mac was working but not on the server
So I think I'd borked this one myself.
I'd been lazy and left function datatablePersons() in PersonsController.php using an old 'count' method, relying on long-defunct relationships (that caused n+1, so had to be binned), hence it wobbling over an actions class whenever that relationship was called upon.
Datatable functions in other controllers (with a cleaner 'count' method) work fine, so I've just rewritten datatablePersons() to use the same method.
I've not quite got the query right (in eloquent, at least) yet - see this question here: mysql join ON and AND to laravel eloquent - but the class not found error has certainly gone away.
I'm (massively) guessing that the classmap on the local machine hadn't been flushed since whatever was removed was removed, while the production machine is rebuilt every push, hence the disparity...?
Either way, it's no longer an issue.

atk4 schema generator error

I get the following error when running:
class page_generator extends Page_SchemaGenerator {
}
Application Error: requires jQuery or jUI support
BaseException, code: 0
C:\projects\wamp\atk4\atk4\lib\Form\Submit.php:33
Where did you get such class? What version of ATK4 are you using?
Anyway, you have to add jUI class iun your Frontend class.
Sorry, but I couldn't remain silent and will say that - schema generators are evil !!! :)
There are only very rare case when they are OK. One of such cases is if you actually require dynamically changeable DB structure. If that's the case, then better use this add-on: https://github.com/atk4/atk4-addons/tree/master/dynamic_model
Add the following to your lib/Frontend.php
$this->add('jUI');
And as #DarkSide said - schema generators are evil.
There is also on-the-fly generator controller for model:
https://github.com/atk4/atk4-addons/tree/master/dynamic_model

Selenium phpunit testing without DB

Intro:
I have a Yii webapp which I want to test using phpunit and selenium testing, but here is the catch, I do not use a DB. I communicate with an API which integrates with Yii's activeRecord (https://github.com/Haensel/ActiveResource).
Situation:
So I have phpunit test working and I have a running Selenium stand alone server running as well. I do not use the FF plugin. I run it as a unit test:
<?php
class TestTest extends WebTestCase
{
public $fixtures=array(
//'posts'=>'Post',
);
public function testShow()
{
$this->open('site/login');
// verify the sample post title exists
$this->assertTextPresent($this->posts['sample1']['title']);
// verify comment form exists
$this->assertTextPresent('Password');
}
}
?>
But it keeps trying to connect to the database, which doesn't exist. My webapp works fine without the database connection so I know it doesn't need it.
Question:
So what I want to know is whether it is actually possible (I am new to Yii, but lots of MVC experience)?
How can I "set it up" to not look for a DB resource?
Has anyone done this and maybe have a few pointers or guide etc?
thanks alot!
"How can I "set it up" to not look for a DB resource" -> I believe that you can do that in the same file "protected/config/main.php", that you set it up to look for a DB.

Categories