Yii2 console script not working - console

I want to automatically download my database backup weekly. I'm using xampp on windows. I've google around and found that I've to make use of windows task scheduler and the action script in my console controller. I've read this and this and tried running the command from command prompt. I'm getting 'Unknown command'.
My code in console controller for now just for testing
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
/**
* Cron controller
*/
class TestController extends Controller {
public function actionIndex() {
echo "cron service runnning";
}
}
And my main config file
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
'modules' => [
'rbac' => [
'class' => 'johnitvn\rbacplus\Module'
]
],
'params' => $params,
];
The error I'm getting

Make sure you have TestController.php file in console/controllers folder and its name is written correctly.
Then from project root folder you can call your command like that:
php yii test/index
or just:
php yii test
(because index is a default action (configured in $defaultAction) and you can omit it).
If you are outside of project folder, make sure to provide correct path:
php /path/to/project/folder/yii test

Related

Why is Oneup/UploaderBundle so slow to upload a 'big' file (1GB)?

In a Symfony project, I have implemented the Oneup/UploaderBundle with the Oneup/FlysystemBundle to upload files to a S3 compatible storage.
I tried to upload a 1GB file, and it took about 3 min using the Aws\S3\S3Client adapter (https://flysystem.thephpleague.com/docs/adapter/aws-s3-v3/), which is way too slow.
oneup_uploader.yaml :
object_scaleway_sync:
frontend: dropzone
storage:
type: flysystem
filesystem: oneup_flysystem.object_scaleway_sync_filesystem
oneup_flysystem.yaml :
oneup_flysystem:
adapters:
xxx_fr_sync.flysystem_adapter:
awss3v3:
client: xxx_fr.sync_s3_client
bucket: 'xxxtest'
prefix: ''
filesystems:
object_scaleway_sync:
adapter: xxx_fr_sync.flysystem_adapter
After that, I tried to upload the same file using directly the S3Client in a controller, and it took about 98 seconds, which is faster, but still too slow for 1GB.
MainController.php :
$client = new S3S3Client([
'region' => 'fr-par',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'version' => 'latest',
'credentials' => [
'key' => 'publickey',
'secret' => 'secretkey'
]
]);
$pathToFile = $this->getParameter('kernel.project_dir') . '/public/big.bin';
$resource = \fopen($pathToFile, 'r');
$result = $client->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'Body' => $resource
]);
return new Response("Ok");
Strangely, this simple plain php script below took 28 seconds to upload the same file :
$s3 = new Aws\S3\S3Client([
'region' => 'fr-par',
'version' => 'latest',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'credentials' => [
'key' => "publickey",
'secret' => "secretkey",
]
]);
$result = $s3->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'SourceFile' => './big.bin'
]);
Why is this script faster than the Symfony method ? Is there a way to optimize the upload speed ?
I tried using the async S3 Simple Client (https://async-aws.com/integration/simple-s3.html) but it returned the error "Could not contact remote server" at the end of the upload.
Same error with the async S3Client (https://async-aws.com/clients/s3.html).

How to store image in Wordpress using Woocommerce Api's in Laravel

I am using Woocommerce api's in Laravel. I have Facing issue to store image in Wordpress. On This stage i have no idea what i do. I have no idea about code to write. Anyone can help how can i store image from using Laravel in Wordpress. Thanks
I believe this should give you an idea where to start.
Woocommerce has a good PHP Library for their API. I found a Laravel package which is a wrapper for Woocommerce API, https://github.com/Codexshaper/laravel-woocommerce
1. Install the Woocommerce plugin in WordPress and generate an API key and Secret.
https://docs.woocommerce.com/document/woocommerce-rest-api/
2. Install the package in Laravel
composer require codexshaper/laravel-woocommerce
php artisan vendor:publish --tag=woocommerce
3. Follow Laravel-Woocommerce documentation for configuration and usage
https://codexshaper.github.io/docs/laravel-woocommerce/
4. Remember to update your .env, with the information you got from step 1
WOOCOMMERCE_STORE_URL=YOUR_WEBSITE_URL
WOOCOMMERCE_CONSUMER_KEY=API_CONSUMER_KEY
WOOCOMMERCE_CONSUMER_SECRET=API_CONSUMER_SECRET
5. Setup a controller in Laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Codexshaper\WooCommerce\Facades\Product;
class ProductController extends Controller
{
public function create(Request $request){
try{
//#todo idealy, the data should be coming from $request->all() or something
$data = [
'name' => 'Simple Product',
'type' => 'simple',
'regular_price' => '10.00',
'description' => 'Simple product full description.',
'short_description' => 'Simple product short description.',
'categories' => [
[
'id' => 1
],
[
'id' => 3
],
[
'id' => 5
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg'
],
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg'
]
]
];
$product = Product::create($data);
dd($product); //#todo
}catch(\Exception $e){
dd($e); //#todo
}
}
}

how to implement hook_theme drupal 8?

Im new to drupal,I need to render a form so i have to implement hook theme, my confusion is Under which directory I should create hook theme file in drupal 8?
// my_module.module
function custom_module_theme($existing, $type, $theme, $path) {
return array(
'customize_form' => array(
'variables' => array(
'Custom_Form' => NULL
),
'render element' => 'form'
),
);
}
where I have to put above file in drupal 8??
Thanks in advance.
In your .module file
File location - module/custom/MODULENAME/MODULENAME.module
/**
* #file
* Twig template for render content
*/
function MODULENAME_theme($existing, $type, $theme, $path) {
return [
'theme_name_template' => [
'variables' => ['flag' => NULL],
],
];
}
To Use theme function use below code
return ['#theme' => 'theme_name_template', '#flag' => 1];
If i got it right you want the folder to place your module, right? You have to put your module in a folder under
/modules/custom/your_module_folder or /sites/all/modules/your_module_folder

Yii2 module (not under /vendor folder) class not found in config/main.php

I've created a module under folder api (which itself is same level as backend & frontend in yii2 advanced app).
Folder structure:
api
-- common
------ controllers
------ models
-- config
-- modules
------ v1
---------- controllers
---------- models
-- runtime
-- tests
-- web
In api/config/main.php:
return [
'id' => 'app-api',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'modules' => [
'v1' => [
'basePath' => '#app/modules/v1',
'class' => 'api\modules\v1\Module'
]
],
I get error:
ReflectionException
Class api\modules\v1\Module does not exist
The class is definitely there.
I've run a composer dumpautoload (no errors).
urlManager in config/main.php:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
'v1/site/index' => 'v1/site/index', //module/controller/action
],
]
Any help much appreciated,
thanks
OK got it:
in common/config/bootstrap.php, add:
Yii::setAlias('#api', dirname(dirname(__DIR__)) . '/api');
Then in config/main.php use:
'modules' => [
'v1' => [
'basePath' => '#api/modules/v1',
'class' => 'api\modules\v1\Module'
]
],
This seems to work, thanks guys
Thanks, gvanto. Also check whether you include common/config/bootstrap.php in \api\web\index.php . Like here
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require (__DIR__ . '/../../common/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
$application = new yii\web\Application($config);
$application->run();
that was my mistake. Maybe it will help someone

Drupal 7 Migrate Module shows "No migration groups defined". Why is my Migration Class not registering?

I am trying to migrate content (at this point user accounts specifically) from a legacy site into Drupal 7 using the Drupal Migrate module but for some reason the custom site migration class is not being registered. The only indication that something is wrong is the lack of any output when running drush migrate-status, and the output "No migration groups defined" when visiting http://<drupal_root_url>/admin/content/migrate in a web browser. The migrate, migrate_ui, and pinpics_migration modules have all been enabled via the Drupal 7 admin dashboard. I have tried using drush to clear all caches and register the migration classes, as well as registering the migration classes using the web UI to no avail. drush was run from the folder with the settings.php file /<drupal_root_path>/sites/default/
drush cc all && drush migrate-register && drush migrate-status
I have the following files located in
/<drupal_root_path>/sites/all/modules/custom/pinpics_migration/
pinpics_migration.info
pinpics_migration.migrate.inc
pinpics_migration.module
I have tried placing the file containing the custom migration class implementation pinpics_users.inc in the same directory as the files above, as well as in:
/<drupal_root_path>/includes/
Here are the file contents:
pinpics_migration.info:
<?php
name = "Pinpics Migration"
description = "Module to migrate legacy site to Drupal 7 site"
package = "Migration"
core = 7.x
dependencies[] = migrate
files[] = pinpics_migration.module
files[] = pinpics_users.inc
?>
pinpics_migration.migrate.inc:
<?php
function pinpics_migration_migrate_api() {
$api = array( 'api' => 2 );
return $api;
}
?>
pinpics_migration.module:
<?php
define("SOURCE_DATABASE", "pinpics_db");
?>
pinpics_users.inc: (Stripped of some helper functions, and specific implementation details)
<?php
/// Stripped some helper functions that were used by pinpicsUserMigration::prepareRow() below
class pinpicsUserMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('user_migration_group'));
$this->description = t('Migrate pinpics.com users');
$source_fields = array(
'uid' => t('User ID'),
'roles' => t('The set of roles assigned to a user.'),
'password' => t('MD5 hash of User Password'),
'email' => t('User email address'),
'name' => t('Username'),
'created' => t('Timestamp that legacy account was created.'),
'status' => t('The staus of the User account'),
'logintime' => t('Timestamp that the User last logged in.')
);
$query = db_select(SOURCE_DATABASE.'.users', 'u')
->fields('u', array('uid', 'roles', 'password', 'email', 'name', 'created', 'logintime', 'status'))
->condition('status', '0', '=')
->condition('inactive', '0', '=')
->condition('email', '', '<>')
->condition('loginip', '', '<>')
->orderBy('uid', 'ASC');
$this->source = new MigrateSourceSQL($query, $source_fields);
$this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'non null' => TRUE,
'description' => 'Legacy Unique User ID',
'alias' => 'u',
)
),
MigrateDestinationUser::getKeySchema()
);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('name', 'name');
$this->addFieldMapping('pass', 'password');
/// Many addFieldMapping() statement stripped out for brevity.
}
public function prepareRow($current_row) {
/// Stripped implementation details for massaging data to prepare for Drupal 7.
return TRUE;
}
}
?>
I am new to Drupal, and have been using the following references to implement the migration.
Drupal 6 to Drupal 7 via Migrate 2
Getting started with Migrate
Has anyone encountered this problem before, or know how to go about finding out what is wrong?
Try these steps:
Visit your sites modules page /admin/modules to trigger rebuilding of cached PHP.
Disable and enable your module to get a new class registered.

Resources