Lock wait timeout exceeded try restarting transaction in mysql — May 30, 2017

Lock wait timeout exceeded try restarting transaction in mysql

You can set variable innodb_lock_wait_timeout=100 for lock time to 100 sec.

mysql> set innodb_lock_wait_timeout=100

Query OK, 0 rows affected (0.02 sec)

mysql> show variables like 'innodb_lock_wait_timeout';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_lock_wait_timeout | 100   |
+--------------------------+-------+

The transaction which is timeout, try to lock table which is hold by another process. and your timeout variable set with little number of second. so it shows error. You can see more status by the command.

SHOW ENGINE INNODB STATUS\G 

You can see list of locked tables by-

 show open tables where in_use>0;

Now see the thread which is using this table

  show full processlist;

now you can kill that thread or wait to complete it.

To get a list of the threads you want to kill off.

SELECT CONCAT('KILL ',id,';') AS run_this FROM information_schema.processlist

You now have a list of the threads you want to kill off.

Git rollback to commit id — May 11, 2017
Ubuntu useful Commands — May 8, 2017
wordpress wp_enqueue_script() and ajax example — March 14, 2017

wordpress wp_enqueue_script() and ajax example


//register script

function load_custom_wp_admin_style($hook) {
if($hook != 'settings_page_swot-email-status') {
return;
}
// Register the script
wp_register_script( 'my_custom_adminscript', plugin_dir_url( __FILE__ ) . 'js/admin/adminscript.js', array('jquery') );
// Localize the script with new data
$translation_array = array(
'cresscap_nonce' => wp_create_nonce('swot-form')
);
wp_localize_script( 'my_custom_adminscript', 'adminscript_swotform', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'my_custom_adminscript' );

}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
/*admin section add scripts*/



/*add menu page in admin area*/
function swot_email_status() 
{

    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => array('0', '1'),
                'compare' => 'IN',
            ),
        ),
    );
    $total_waiting_query = new WP_Query( $args );
    $total_waiting =  $total_waiting_query->post_count;
        // echo "Last SQL-Query: {$total_waiting_query->request}";
    wp_reset_query();


    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => '2',
                'compare' => '=',
            ),
        ),
    );
    $total_sent_query = new WP_Query( $args );
    $total_sent =  $total_sent_query->post_count;
    wp_reset_query();

    echo '
    ';
}
/*admin section enqueue scripts*/
/*add menu page in admin area*/


/*jquery to make a request*/
jQuery(document).ready(function(){
	jQuery('#send_swot_email_submit').click(function(){
		jQuery(this).prop('disabled', true);
		var send_swot_email_result = jQuery('#send_swot_email_result');
		send_swot_email_result.html('Processing...').show();

		jQuery.ajax({
	        type: 'POST',
	        url: ajaxurl,
	        dataType: 'json',
	        data: {
	            'action':   'send_swot_email_submit',
	            'cresscap_nonce' : adminscript_swotform.cresscap_nonce
	        },
    
	    success: function (response) {
	    	jQuery('#send_swot_email_submit').prop('disabled', false);
	        // console.log(response);
	        send_swot_email_result.html('');
	        if( response.failed_mails )
			{
				var result;
				result = 'Not able to deliver email to : '+ response.failed_mails;
				send_swot_email_result.html(result).show();
			}
			if( response.success_mails )
			{
				var result;
				result = 'Email successfully delivered to : '+ response.success_mails;
				send_swot_email_result.html(result).show();
				// setTimeout(function(){ location.reload(true); }, 2000);

			}
	       
	    }

    });
/*jquery to make a request*/

Ubuntu unrar a file — March 10, 2017
Css wrap words in div or in table column — March 8, 2017
wordpress ACF create front end form, submit and edit —

wordpress ACF create front end form, submit and edit

always add acf_form_head(); in head tag
acf_form_head();

$options = array(
'post_id' => $_GET['listing_edit'], // $user_profile,
'field_groups' => array(1199),
'submit_value' => 'Submit',
// ‘uploader’ => ‘basic’,
'class' => 'btn green'

);

acf_form( $options );

$value = get_field( 'add_feed_links_here', $_GET['listing_edit'] );
print_r($value);

And to add validation to this field
add_filter('acf/validate_value/name=add_feed_links_here', 'my_acf_validate_value', 10, 4);

function my_acf_validate_value( $valid, $value, $field, $input ){

// bail early if value is already invalid
if( !$valid ) {

return $valid;

}

// load image data
$data = wp_get_attachment_image_src( $value, 'full' );
$width = $data[1];
$height = $data[2];

if( $width < 960 ) {

$valid = 'Image must be at least 960px wide';

}

// return
return $valid;

}