Thursday, August 17, 2017

WordPress - init hook seems to be fired more than once

init hook should be fired only once in WP

If it appears as being fired more than once, it's probably because there was a redirect and/or 404 error (even for a PNG, it's going to trigger the full WP Load).



Also, there might be multiprocess/multithread execution. Every page load can run multiple wp processes in case of 404 errors or redirects! And they can enter a race condition!

Saturday, August 12, 2017

mysql 5.7 - disabling STRICT mode

If your app was written for older versions of MySQL and is not compatible with strict SQL mode in MySQL 5.7, you can disable strict SQL mode. For example, apps such as WHMCS 6 and Craft 2 do not support strict SQL mode.

If you're using WHMCS 7, see our article on customizing MySQL for WHMCS 7.
To disable strict SQL mode, SSH in to your server as root and create this file:

/etc/mysql/conf.d/disable_strict_mode.cnf
Open the file and enter these two lines:

[mysqld]
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart MySQL with this command:

sudo service mysql restart
This change disables two SQL mode settings, STRICT_TRANS_TABLES and ONLY_FULL_GROUP_BY, that were added in MySQL 5.7 and cause problems for some older applications.

Full details here

Friday, August 4, 2017

npm, Homestead, and Windows - EIO npm error - solved

If you are using npm inside of a Homestead box which is being hosted in Windows, and you see a "Exit status 1" error , or EIO error thrown by npm scripts, make sure that you have downloaded the npm packages inside of Homestead box, and not in Windows.

Apparently, there could be some differences in encoding / character set which can result in npm errors inside of Homestead box.

So, inside your Homestead box, remove the node_modules file and re-run npm install. Now you should be able to run npm scripts normally.

Tuesday, August 1, 2017

Laravel Cashier - There are no commands defined in the "cashier" namespace. [Solved]

In Laravel 5.4, when trying to use Laravel\Cashier, the following error can sometimes occur:
There are no commands defined in the "cashier" namespace.

The solution is to manually create the migration file and execute it:

Run this:
php artisan make:migration add_cashier_table_fields
And then, in the created empty file, add this:

[code]

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddCashierTableFields extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //

         Schema::table('users', function ($table) {
            $table->string('stripe_id')->nullable();
            $table->string('card_brand')->nullable();
            $table->string('card_last_four')->nullable();
            $table->timestamp('trial_ends_at')->nullable();
        });
        Schema::create('subscriptions', function ($table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->string('name');
            $table->string('stripe_id');
            $table->string('stripe_plan');
            $table->integer('quantity');
            $table->timestamp('trial_ends_at')->nullable();
            $table->timestamp('ends_at')->nullable();
            $table->timestamps();
        });
     
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}


[/code]

Now, you can execute the command:
php artisan migrate


Original solution is here:
http://itsolutionstuff.com/post/how-to-solve-there-are-no-commands-defined-in-the-cashier-namespace-in-laravel-5example.html

PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...