yii queue doesn't detect jobs in database - yii2

I'm trying to run a queue using yii so I can do some tests, but whenever I type the command yii queue/run, no job seems to be put in waiting,
This is to send the information of an ID and status of a job that when the conditions are met, will be ran in the main page
This is the code that sends the data into the queue:
class HorarioController extends Controller
{
public function actionBuscar()
{
$hora = date("H").":00".":00";
$dia = date("N");
$horarios = Horarios_Equipos::find()->all();
foreach($horarios as $horario)
{
echo $horario->id_equipo."\n";
echo $horario->estado."\n";
//enviar a cola
Yii::$app->queue->push(
new HorarioJob([
'id_equipo' => $horario->id_equipo,
'estado' => $horario->estado,
])
);
}
return ExitCode::OK;
}
}
And this is the code that does the action in the queue
public function execute($queue)
{
if($estado == '1'){
if($pin == 1)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDa=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 2)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDb=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 3)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDc=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 4)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDd=ON');
return $this->redirect(['view', 'id' => $id]);
}
}
if ($estado == 0){
if ($pin == '1')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDa=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '2')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDb=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '3')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDc=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '4')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDd=OFF');
return $this->redirect(['view', 'id' => $id]);
}
}
}
}
This is what shows when I run yii queue/run:
C:\xampp\htdocs\accontrol>yii queue/run
C:\xampp\htdocs\accontrol>
And if I run yii queue/info it only shows this:
C:\xampp\htdocs\accontrol>yii queue/info
Jobs
- waiting: 0
- delayed: 0
- reserved: 0
- done: 0
As fas as I know the files where the queue functions are written are correct and I should be able to run the queue/run command, at least get an error to see where I'm wrong, but it just doesn't

Found the problem, PHP had the timezone configured incorrectly so when it tried to search for the time on the database it wouldn't match with the time it had configured, had to modify the php.ini document to set the correct timezone, If you're having this problem to enter the php.ini document you can do it via the control panel: in the Apache section click the config button and select the PHP(php.ini)
Then use the find option and search for timezone, and then you may type the timezone of your area, in my case its America/Mexico_City
Heres the link where you can find the timezones: https://www.php.net/manual/es/timezones.php

Related

Connecting Application to Mysql Database CPanel, utf8_general_ci

I have software or an application on a MacBook called Nano Hotel Booking, I am trying to connect it to my CPanel server but I get the error Unknown collation: 'utf8_general_ci'. Everything else works besides the error for UTF8 I have checked the setting on the Data
`
<?php
$database_host = "localhost";
$database_user = "12345";
$database_password = "12345";
$database_name = "12345";
$db_access_token = "";
$return_format = (isset($_REQUEST['return_format'])) ? $_REQUEST['return_format'] : 'json';
$res = array('success' => true, 'errormsg' => '', 'data' => '');
try
{
$filename = (isset($_FILES['uploadedfile']['name'])) ? $_FILES['uploadedfile']['name'] : '';
if(trim($filename))
{
$upload_dir = 'data';
$ar = explode('___', basename($_FILES['uploadedfile']['name']));
if(sizeof($ar) != 3) throw new Exception('Bad file name '.basename($_FILES['uploadedfile']['name']));
if(!trim($ar[0]) || !trim($ar[1])) throw new Exception('Bad folder name');
if(!trim($ar[2])) throw new Exception('Bad file name '.$ar[2]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[0]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[1]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[2]);
if(file_exists($upload_dir)) #unlink($upload_dir);
if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_dir))
throw new Exception('Can not upload file '.$upload_dir);
} else
{
$params = $_REQUEST;
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if(!$action) throw new Exception('Action not found.');
$enc_request = (isset($_REQUEST['enc_request'])) ? $_REQUEST['enc_request'] : '';
$params = #json_decode(trim(base64_decode($enc_request)));
if($params == false) throw new Exception('Request is not valid');
$params = (array)$params;
// Connect user
$s_key = '';
if(isset($params['db_access_token']))
{
$s_key = $params['db_access_token'];
}
if($s_key !== $db_access_token) throw new Exception('Bad user.');
$controller = new apiController($database_host, $database_user, $database_password, $database_name);
if($action === 'checkconnection') throw new Exception('ok');
if(method_exists($controller, $action) === false ) throw new Exception('Action is invalid.');
$controller->request = $params;
$res['data'] = $controller->$action();
}
} catch(Exception $e)
{
$res['success'] = 0;
$res['errormsg'] = $e->getMessage();
}
switch($return_format)
{
case 'json': print(json_encode($res)); exit; break;
case 'xml': print(arrayToXml($res)); exit; break;
}
class apiController
{
public $request = array();
protected $conn;
public function __construct($host = '', $user = '', $psw = '', $dbname = '')
{
#$this->conn = mysqli_connect($host, $user, $psw, $dbname);
if(!$this->conn) throw new Exception(mysqli_connect_errno().' '.mysqli_connect_error());
#mysqli_query($this->conn, "SET CHARACTER SET utf8_general_ci");
#mysqli_query($this->conn, "set names utf8");
#mysqli_query($this->conn, "SET collation_connection = utf8_general_ci");
}
public function select()
{
$sql = (isset($this->request['sql'])) ? $this->request['sql'] : '';
$array = array();
if(is_array($sql))
{
foreach($sql as $value)
{
$arr = $this->selectOne($value);
$array[] = (sizeof($arr) > 0) ? $arr[0] : array();
}
} else
{
$array = $this->selectOne($sql);
}
if($this->conn) #mysqli_close($this->conn);
return $array;
}
public function selectOne($sql = '')
{
if(!trim($sql)) throw new Exception('Empty sql.');
$offset = (isset($this->request['offset'])) ? (int)$this->request['offset'] : 0;
$limit = (isset($this->request['limit'])) ? (int)$this->request['limit'] : 20;
if($limit) $sql .= ' LIMIT '.$offset.', '.$limit;
$result = mysqli_query($this->conn, $sql);
if(!$result) throw new Exception(mysqli_error($this->conn));
$rows = mysqli_num_rows($result);
if($rows <= 0)
{
mysqli_free_result($result);
mysqli_close($this->conn);
return array();
}
$array = array();
$fields = mysqli_num_fields($result);
while ($row = mysqli_fetch_row($result))
{
$onerow = array();
for ($i=0; $i < $fields; $i++) $onerow[] = $row[$i];
$array[] = $onerow;
}
mysqli_free_result($result);
return $array;
}
public function execute()
{
$sql = (isset($this->request['sql'])) ? $this->request['sql'] : '';
$array = array();
if(is_array($sql))
{
foreach($sql as $value)
{
$array = $this->executeOne($value);
}
} else
{
$array = $this->executeOne($sql);
}
if($this->conn) #mysqli_close($this->conn);
return $array;
}
public function executeOne($sql = '')
{
$lastid = '';
$result = null;
if(!trim($sql)) throw new Exception('Empty sql.');
$str = strtoupper($sql);
if((strpos($str, 'CREATE') !== false)
&& (strpos($str, 'TABLE') !== false)
)
{
$sql = str_ireplace ('AUTOINCREMENT' , 'AUTO_INCREMENT', $sql);
$sql = str_ireplace ('COLLATE NOCASE' , '', $sql);
}
if((strpos($str, 'INSERT') !== false)
&& (strpos($str, 'INTO') !== false)
&& (strpos($str, 'VALUES') !== false)
&& (strpos($str, '(0,') !== false)
)
{
$result = mysqli_query($this->conn, 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"');
if(!$result) throw new Exception(mysqli_error($this->conn));
}
$result = mysqli_query($this->conn, $sql);
if(!$result) throw new Exception(mysqli_error($this->conn));
if((strpos($str, 'INSERT') !== false)
&& (strpos($str, 'INTO') !== false)
&& (strpos($str, 'VALUES') !== false)
)
{
$result = mysqli_query($this->conn, 'SELECT LAST_INSERT_ID()');
if (mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_row($result))
{
$lastid = $row[0];
break;
}
}
}
$array = array();
$array[] = array($lastid);
if($result !== true) mysqli_free_result($result);
return $array;
}
public function getFieldFromSql($sql = '', $def = '')
{
if(!$sql) return $def;
$this->request['offset'] = 0;
$this->request['limit'] = 1;
$arr = $this->selectOne($sql);
if(sizeof($arr) == 0) return $def;
if(sizeof($arr[0]) == 0) return $def;
return $arr[0][0];
}
public function getFieldsFromSql($sql = '', $def = '')
{
if(!$sql) return $def;
$this->request['offset'] = 0;
$this->request['limit'] = 1;
$arr = $this->selectOne($sql);
if(sizeof($arr) == 0) return $def;
return $arr[0];
}
public function getArrayFromSql($sql = '')
{
if(!$sql) return array();
$this->request['offset'] = 0;
$this->request['limit'] = 100000;
return $this->selectOne($sql);
}
public function runScript()
{
$php = (isset($this->request['sql'])) ? trim($this->request['sql']) : '';
$nano = $this;
$php_res = #eval($php);
if($this->conn) #mysqli_close($this->conn);
if(is_array($php_res))
{
if(sizeof($php_res) > 0)
{
if(is_array($php_res[0])) return $php_res;
}
return array($php_res);
}
$array = array();
$array[] = array($php_res);
return $array;
}
}
?>
`
I have tried changing the UTF8 to almost everything else.

how can i get value from another CRUD in my json

i have json return values from order crud how can i make it return also value from User Crud by user ID
this is my code now
public function vendorindex(Request $request)
{
$user = Auth::user();
if(isset($user->id)){
$order = Order::where('vendor_id', $user->id)->get();
}else{
$order = null;
}
return response()->json($order);
}
i tried to do this but not work with me to replace another value with the value that i want
public function vendorindex(Request $request)
{
$user = Auth::user();
if(isset($user->id)){
$order = Order::where('vendor_id', $user->id)->get();
foreach($order as $orders){
$mobile = User::where($user->mobile);
$created_at = Order::where($orders->created_at);
$phonenumber = array(
'mobile' => $mobile,
'created_at' => $created_at
);
$orders->created_at = $phonenumber;
}
}else{
$order = null;
}
return response()->json($order);
}

image not insert in mysql using codeigniter

I am trying to insert images in mysql database with other data but its shows error.
its shows the $msg of not saved & repeat data of view file maybe due to $error which i set.
PS: I set 'image' datatype varchar in database.
here is my view file:
<input type="file" class="form-control-file" name="image" id="exampleInputFile" >
this is my controller:
public function save()
{
$this->load->model('Partner_model');
$feature = $this->input->post('feature');
$config['upload_path'] = './uploads/files';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('partner_profile', $error);
}
else
{
$user_data= array(
'pname' => $this->input->post('pname'),
'type' => $this->input->post('type'),
'address' => $this->input->post('address'),
'about' => $this->input->post('about'),
'city' => $this->input->post('city'),
'code' => $this->input->post('code'),
'state'=>$this->input->post('state'),
// 'image'=>$this->upload->do_upload('image')
'feature'=>implode(",",$feature),
'image' => $this->upload->data()
);
}
if($this->Partner_model->save($user_data))
{
$msg = "save sucesss" ;
}
else
{
$msg = "not save";
}
$this->session->set_flashdata('msg', $msg);
$this->load->view('partner_profile');
}
}
& this is my model:
public function save($data)
{
return $this->db->insert('property', $data);
}
Your form must have the multipart attribute in HTML file like below :
If you're using form helper, then it should be
<?php echo form_open_multipart('/save');?>
Else your form should have the enctype attribute like below
<form enctype="multipart/form-data">
Then the uploaded data result $this->upload->data() will come in array. So you can't store your array in mysql column. So you need to get the filename from $this->upload->data() and store it in a variable like below.
Your Controller should be
public function save(){
$this->load->model('Partner_model');
$feature = $this->input->post('feature');
$config['upload_path'] = './uploads/files';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image')){
$error = array('error' => $this->upload->display_errors());
$this->load->view('partner_profile', $error);
}else{
$imageArray = $this->upload->data();
$image = $imageArray['file_name'];
$user_data= array(
'pname' => $this->input->post('pname'),
'type' => $this->input->post('type'),
'address' => $this->input->post('address'),
'about' => $this->input->post('about'),
'city' => $this->input->post('city'),
'code' => $this->input->post('code'),
'state'=>$this->input->post('state'),
'feature'=>implode(",",$feature),
'image' => $image
);
}
if($this->Partner_model->save($user_data)) {
$msg = "save sucesss" ;
}else {
$msg = "not save";
}
$this->session->set_flashdata('msg', $msg);
$this->load->view('partner_profile');
}

add folder to folder using google drive API

The script below is creating folders within a parent folder using
"google drive API". It works perfectly however, after a while (20 folders or so) it is not working anymore.
No error message just no more folder creation within the parent folder.
It goes somewhere else!
To enable that creation a "service account" was created and parent folder is share between "personal google account" and "service account"
Can someone provide help please?
php function send_google_drive($id,$fileno,$filename1,$filename2){
global $wpdb;
require(ABSPATH.'/wp-content/themes/enemat/googledrives/vendor/autoload.php');
$client = getClient();
$service = new Google_Service_Drive($client);
if(!empty($filename1)){
$results = $service->files->listFiles();
foreach ($results->getFiles() as $item) {
if ($item['name'] == 'ENEMAT CRM FILES') {
$folderId = $item['id'];
break;
}
}
$parentid = $folderId;
$childid = "";
foreach ($results->getFiles() as $item) {
if ($item['name'] == $fileno) {
$childid = $item['id'];
break;
}
}
if(empty($childid)){
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => $fileno,
'parents'=>array($parentid),
'mimeType' => 'application/vnd.google-apps.folder'));
$file = $service->files->create($fileMetadata, array(
'fields' => 'id'));
$folderId = $file->id;
}else{
$folderId = $childid;
}
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setType('anyone');
$newPermission->setRole('reader');
$service->permissions->create($folderId, $newPermission);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => array(basename($filename1)),
'parents' => array($folderId)
));
$content = file_get_contents($filename1);
$files = $service->files->create($fileMetadata, array(
'data' => $content,
'uploadType' => 'resumable',
'fields' => 'id'));
$fileids = $files->id;
$docusignorgs = "https://drive.google.com/open?id=".$fileids."";
$folderslink = "https://drive.google.com/drive/folders/".$folderId."";
#unlink(ABSPATH."wp-content/themes/enemat/pdfs/".basename($filename1));
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setType('anyone');
$newPermission->setRole('reader');
$service->permissions->create($fileids, $newPermission);
}
if(!empty($filename2)){
$results = $service->files->listFiles();
foreach ($results->getFiles() as $item) {
if ($item['name'] == '46 - CONTRAT PARTENARIAT') {
$folderId = $item['id'];
break;
}
}
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => array(basename($filename2)),
'parents' => array($folderId)
));
$content = file_get_contents($filename2);
$files = $service->files->create($fileMetadata, array(
'data' => $content,
'uploadType' => 'resumable',
'fields' => 'id'));
$fileids1 = $files->id;
$contractdrivelink = "https://drive.google.com/open?id=".$fileids1."";
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setType('anyone');
$newPermission->setRole('reader');
$service->permissions->create($fileids1, $newPermission);
}
}
?
The reason there is no error message is because your code has no error handling! If GDrive fails to do something, it returns an error code and message to explain why. Your code should be catching that error and displaying it.
My guess is that you are hitting a rate limit. To see if this is the cause or not, add a 2 second delay between each folder creation. If it no runs correctly, you know that rate limiting is your problem.

array saving cakephp 3 savemany

Hi can someone know this i am beginner in Cakephp i tried to upload multiple images but it wont save.
Controller:
public function add() {
if ($this->request->is('post')) {
//$data = $this->request->getData();
if(!empty($_FILES['photo']['name'])){
$count = count($_FILES['photo']['name']);
for ($i=0; $i < $count; $i++) {
$filename = $_FILES['photo']['name'][$i];
$type = $_FILES['photo']['type'][$i];
$tmp = $_FILES['photo']['tmp_name'][$i];
$error = $_FILES['photo']['error'][$i];
$size = $_FILES['photo']['size'][$i];
$uploadPath = '../uploads/files/';
$file[$i]['user_id'] = $this->Auth->user('id');
$file[$i]['filename'] = $filename;
$file[$i]['file_location'] = $uploadPath;
$file[$i]['file_type'] = $type;
$file[$i]['file_size'] = $size;
$file[$i]['file_status'] = 'Active';
$file[$i]['created'] = date("Y-m-d H:i:s");
$file[$i]['modified'] = date("Y-m-d H:i:s");
}
$table = TableRegistry::get('files');
$entities = $table->newEntities($file);
if($table->saveMany($entities)) {
$this->Flash->success(__('File has been uploaded and inserted successfully.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('Unable to upload file, please try again.'));
}
} else {
$this->Flash->error(__('Please choose a file to upload.'));
}
}
}
but when i tried to debug all good but in saving it wont work! does my code has problem, can someone help me how to fix my add function
View:
echo $this->Form->input('photo[]', ['type' => 'file','multiple' => 'true','label' => 'Upload Multiple Photos']);
You are trying to save one record once using saveMany().
public function add()
{
if ($this->request->is('post')) {
$table = TableRegistry::get('files');
$uploadPath = '../uploads/files/';
if(!empty($_FILES['photo'])){
foreach ($_FILES['photo'] as $EachPhoto) {
$data[] = [
'user_id' => $this->Auth->user('id'),
'filename' => $EachPhoto['name'],
'file_location' => $uploadPath,
'file_type' => $EachPhoto['type'],
'file_size' => $EachPhoto['size'],
'file_status' => 'Active',
'created' => date("Y-m-d H:i:s")
];
}
$entities = $table->newEntities($data);
if($this->Files->saveMany($entitie)) {
$this->Flash->success(__('File has been uploaded and inserted successfully.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('Unable to upload file, please try again.'));
}
} else {
$this->Flash->error(__('Please choose a file to upload.'));
}
}
}