Yii application migrating to linux server - php

Problem in accessing the load modules,when migrated to Linux servers.
It does not show any errors but failed to fetech the results.
Works fine in windows os.
Initial problem was the table names case sensitive in Linux and window non-case sensitive.
I renamed the table names
RENAME TABLE main TO Main
Model
class ListModel extends CActiveRecord {
const STATUS_PENDING = 0;
public static function model($className=__CLASS__) {
return parent::model($className);
}
public function tableName() {
return 'list_model';
}
public function rules() {
return array(
array('list_id,list_title,list_user,list_status', 'required'),
array('list_title', 'length', 'max' => 255),
array('list_id,list_status', 'numerical', 'integerOnly' => true),
);
}
public function attributeLabels() {
return array(
'list_id' => 'Id',
'list_title' => 'Title',
'list_user' => 'User',
'list_status' => 'Status',
);
}
public function search(){
$criteria = new CDbCriteria();
$criteria->compare('list_id',$this->list_id, true);
$criteria->compare('list_title',$this->list_title, true);
$criteria->compare('list_user',$this->list_user
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array('defaultOrder'=>'daillisting_complain_id DESC'),
));
}
public static function getCountPending(){
$sql = "SELECT COUNT('list_id') FROM list_model WHERE list_status=".self::STATUS_PENDING;
return (int) Yii::app()->db
->createCommand($sql)
->queryScalar();
}
}
//View
$pending = ListModel::getCountPending();
//does not returns any result and fails
what is the error with the models not fetching the data

While in Windows server they are not Case sensitive
But Whereas in the Linux it is case sensitive.
You Could Check for the Naming convention for controllers,models
Hope this will help you

Related

Get the last inserted row id which is save through model in Yii1.1?

I am using Microsoft SQL Server as my database and yii1.1 framework
$model = new Test();
$model->name = "test";
$model->save();
echo $model->id;
I can't get the id this way shown above the code. It doesn't return anything but the data is being saved to the database.
Here is my test class which I have generated through gii
<?php
class Test extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'test';
}
public function rules()
{
return array(
array('name', 'length', 'max'=>10),
array('id, name', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}

Laravel Eloquent method updateOrCreate exceeds execution time when updating

So the problem is that when I try to update my entity it finds it updates it but gets stuck in a loop probably and doesn't exit. When I check the database, even before the 60 seconds of execution time that I have expires, the values that I have changed are updated.
If i constantly refresh (and here is where it gets crazy) the updated at values for other lectures starts to change every second while it executes this loop.
When creating (not finding the id on the condition It creates it without a problem)
I have Lectures which looks like this:
class Lecture extends Model
{
use Searchable;
use SoftDeletes;
protected $primaryKey = 'id';
protected $touches = ['themes', 'educationTypes', 'subjects'];
protected $fillable= [
'name', 'description', 'user_id', 'field_id', 'approved'
];
public static function boot()
{
parent::boot();
static::saved(function ($model) {
$model->themes->filter(function ($item) {
return $item->shouldBeSearchable();
})->searchable();
});
}
public function user(){
return $this->belongsTo('App\User')->with('companies');
}
public function geographies(){
return $this->belongsToMany('App\Geography');
}
public function educationTypes(){
return $this->belongsToMany('App\EducationType', 'lecture_education_type')->withTimestamps();;
}
public function themes(){
return $this->belongsToMany('App\Theme','lecture_theme', 'lecture_id', 'theme_id')->withTimestamps();;
}
public function subjects(){
return $this->belongsToMany('App\Subject', 'lecture_subject')->withTimestamps();;
}
public function cases(){
return $this->belongsToMany(
'App\CompanyCase' ,
'case_company_lecture',
'lecture_id',
'case_id',
'id',
'id')->withTimestamps();
}
public function companies(){
return $this->belongsToMany(
'App\Company' ,
'case_company_lecture',
'lecture_id',
'company_id',
'id',
'id'
);
}
public function field(){
return $this->belongsTo('App\Field');
}
public function toSearchableArray()
{
$this->themes;
$this->user;
$this->educationTypes;
$this->subjects;
$this->geography;
return $this->toArray();
}
}
This is the controller:
public function storeLecture(Request $request) {
$lecture_id = $request->get('lecture_id');
// It gets stuck between the comments
$lecture = Lecture::updateOrCreate(['id' => $lecture_id],
[
'name'=> request('name'),
'description'=> request('description'),
'user_id'=> request('user_id')]
);
// and doesn't update the themes, edu types subjects and etc.
$company_id = $request->get('company_id');
$company = Company::find(request('company_id'));
$lecture->companies()->sync([$company->id]);
$eduTypes= $request->get('education_types');
$themes= $request->get('themes');
$subjects = $request->get('subjects');
$geographies = $request->get('geographies');
$lecture->themes()->sync($themes);
$lecture->educationTypes()->sync($eduTypes);
$lecture->subjects()->sync($subjects);
$lecture->geographies()->sync($geographies);
$n1 = new Notification();
$n1->send(request('user_id'), 1, 'new_lecture', $lecture->id);
$user = User::where('id', $request->id)->first();
$user_with_companies = $user->load('companies');
$slug = $user_with_companies->companies->first()->slug;
return response(['success' => true]);
}
This is the frontend method sending the request (in between I have a middleware checking if the user is admin (possible to create a lecture) based on the this.selectedExpert.id, which doesn't interfere).
createUpdateLecture() {
const url = `${window.location.origin}/lecture/create/${
this.selectedExpert.id
}`;
this.$http
.post(url, {
education_types: this.allEducationTypes
.filter(el => el.checked)
.map(a => a.id),
themes: this.allThemes.filter(el => el.checked).map(a => a.id),
geographies: this.allGeographies
.filter(el => el.checked)
.map(a => a.id),
subjects: this.allSubjects.filter(el => el.checked).map(a => a.id),
name: this.lecture.name,
description: this.lecture.description,
user_id: this.selectedExpert.id,
company_id: this.company.id,
lecture_id: this.lecture.id
})
.then(res => {
console.log(res);
this.$parent.showLectureCreateModal = false;
// window.location.reload();
});
}
As I can see what is happening I probably use the method really badly but I just want to understand it better for further usage.
After a few days of researching and testing it turns out that it is not the updateOrCreate method causing the problem because I tried with two different functions for creating and updating and the update function was still having the same problem.
The problem is created from Algolia which is used for searching based on different fields in the platform. Fx. in Themes
class Theme extends Model
{
use SoftDeletes;
use Searchable;
protected $touches = ['lectures'];
public function lectures(){
return $this->belongsToMany('App\Lecture');
}
public function toSearchableArray()
{
$this->lectures;
return $this->toArray();
}
}
Removing the searchable from the models did the trick!

YII: Value of variables not saving in the database

I am new to YII. I know this question has been asked a lot of times before nut i can really find an answer. So, please take a look.
I am saving some data in the database from my PaypalController.php
Here is the code of PaypalController.
$transid = $paymentResult['TRANSACTIONID'];
$profileid = $recurringResult['PROFILEID'];
/*var_dump($transid);
var_dump($profileid);
exit;*/
$payment = new Payment;
$payment->user_id = 2;
$payment->feature = 'import sending servers';
$payment->transaction_id = $transid;
$payment->amount = 10;
$payment->profile_id = $profileid;
if($payment->save()){
//var_dump($recurringResult);exit;
//echo "<script>alert('Your payment is succesful');</script>";
$this->redirect('../email-hustler/index');
}else{
print_r($payment->getErrors());
exit;
}
And here is the code of my Payment model
public $user_id;
public $feature;
public $transaction_id;
public $amount;
public $profile_id;
public $is_active;
public function tableName()
{
return '{{payment}}';
}
public function rules()
{
$rules = array(
array('user_id, feature, transaction_id, amount, profile_id, is_active', 'safe'),
);
return CMap::mergeArray($rules, parent::rules());
}
public function attributeLabels(){
return array(
'user_id' => 'user_id',
'feature' => 'feature',
'transaction_id' => 'transaction_id',
'amount' => 'amount',
'profile_id' => 'profile_id',
'is_active' => 'is_active',
);
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
Now the problem is the value of the variables is not saving but the value i am passing static are saved.
var_dump of variables is giving me correct output.
Please help.

Default scope in Yii 1.1

AR model Player:
public function scopes()
{
return array(
'proleague' => array(
'condition' => 'mode = "proleague"',
),
'main' => array(
'condition' => 'mode = "main"',
),
);
}
Using model Player:
Player::model()->
proleague()->
with('startposition')->
findAllByAttributes(... here some condition ...);
^^^ That's all ok. Scope-condition will be executed. But...
In my project I have many places where any scope for Player model doesn't specified and in this cases I need use this scope-condition as default:
'main' => array(
'condition' => 'mode = "main"',
)
If I add defaultScope() method to Player model like this
public function defaultScope()
{
return array(
'condition' => 'mode = "main"',
);
}
the next code
Player::model()->
proleague()->
with('startposition')->
findAllByAttributes(... here some condition ...);
won't run correct. I won't get mode = "proleague" condition, becouse I'll use defaultScope() with mode = "main".
Any suggestions? How can I resolve the problem?
You should just use the resetScope(true) method. It "removes" the defaultScope filter.
$model = Player::model()->resetScope(true)->proleague();
create a new Class for this.
<?php
## e.g. protected/models/
class MyCoreAR extends CActiveRecord
{
/**
* Switch off the default scope
*/
private $_defaultScopeDisabled = false; // Flag - whether defaultScope is disabled or not
public function setDefaultScopeDisabled($bool)
{
$this->_defaultScopeDisabled = $bool;
}
public function getDefaultScopeDisabled()
{
return $this->_defaultScopeDisabled;
}
public function noScope()
{
$obj = clone $this;
$obj->setDefaultScopeDisabled(true);
return $obj;
}
// see http://www.yiiframework.com/wiki/462/yii-for-beginners-2/#hh16
public function resetScope($bool = true)
{
$this->setDefaultScopeDisabled(true);
return parent::resetScope($bool);
}
public function defaultScope()
{
if(!$this->getDefaultScopeDisabled()) {
return array(
'condition' => 'mode = "main"',
);
} else {
return array();
}
}
}
In your code:
// no default scope
$model = Player::model()->noScope()->proleague();
// with default scope
$model = Player::model()->proleague();

Mysql view in yii

I created 2 mysql views, and has generated from them 2 model.
MostPopularCoupon
class MostPopularCoupon extends CActiveRecord
{
public function tableName()
{
return 'most_popular_coupon';
}
public function rules()
{
return array(
array('coupon_id', 'required'),
array('coupon_id', 'numerical', 'integerOnly'=>true),
array('left_coupons', 'length', 'max'=>22),
array('stopped_at', 'safe'),
array('left_coupons, coupon_id, stopped_at', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
);
}
public function attributeLabels()
{
return array(
'left_coupons' => 'Left Coupons',
'coupon_id' => 'Coupon',
'stopped_at' => 'Stopped At',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('left_coupons',$this->left_coupons,true);
$criteria->compare('coupon_id',$this->coupon_id);
$criteria->compare('stopped_at',$this->stopped_at,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
MostActiveCity
class MostActiveCity extends CActiveRecord
{
public function tableName()
{
return 'most_active_city';
}
public function rules()
{
return array(
array('mines', 'length', 'max'=>21),
array('city', 'length', 'max'=>255),
array('mines, city', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array();
}
public function attributeLabels()
{
return array(
'mines' => 'Mines',
'city' => 'City',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('mines',$this->mines,true);
$criteria->compare('city',$this->city,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
But due to no experience, don't know how to use them correctly. I need to substitute company_id in the query to get the data of the company belongs to the current user...
Please relock at your design. You would be better off having model classes of City{} and Coupon{}, then have functions for example MostPopularCoupons inside the Coupon class. You could then call them as functions of the class. For example.
In your model
class Coupon extends CActiveRecord
{
// NOTE: This is important for your alias column.
public $couponCount;
public function tableName()
{
return 'coupon';
}
...
public function MostPopularCoupons()
{
$Criteria = new CDbCriteria();
$Criteria->select = ' count(*) as couponCount ';
$lstCoupons = Coupon::model()->findAll($Criteria);
return $lstCoupons;
}
}
Then, in your controller
$coupon_id = 10;
$model1 = Coupon::model()->findByPK((int)$coupon_id);
$lstCouponCount = Coupon::MostPopularCoupons();

Categories