My two bits on Drupal Migrate user pictures

-
Free tags: 

My two bits on user pictures(Migrate 2.5, D7):

  • Use a separate UserPictureMigration class (you see new IDs from file_managed table)
  • In UserMigration, prepare(), use $this->handleSourceMigration('UserPicture', $row->uid); to assign fid
  • Under normal user picture upload, a new entry on file_usage is created. You may want to insert a row too, during complete() and completeRollback()

Spend me two full day on this. Very confusing:
$this->addFieldMapping('picture')->defaultValue() need an int
but in
public function prepareRow() it shows file path(no effect even file path is correct)
and in
public function prepare() it needs fid

http://drupal.org/node/1349632#comment-7348466

Life on Raspberry Pi command line

Raspberry pi is good for a few things, but you need to get used to full command line interface first.
The recommanded OS - raspbian default do not start a GUI or Xwindows.
And I am experiencing a much stable hardware(encountered overheat problems) under command line(obviously).

So currently I am using it as:
1. a network bridge
2. command line browser
3. hardware development platform

As its power consumption is low, I am very happy to have an "always on" network bridge as a gateway to other devices at home.
In that way, my internal network have some kind of extra security while I still can connect to other internal systems.
On phone ssh to server to restart, quick fix etc very good
Android ssh keyboard

And I just discovered the benefits of using command line interface browser
Recommend w3m over lynx, for supporting chinese characters.

Last, a quick way to develop SPI, IIC, GPIO with python, over network
So I do not need to connect arduino by USB and compile. I HATE COMPILE.
Will share some setup with SPI on rpi later

AttachmentSize
Image icon ws3m joetsuihk-com.png129.3 KB

Custom Views argument Validator: views_plugin_argument_validate

views_plugin_argument_validate
Views' argument is a very useful filter,
With the same views display, but different content types, or authors, or post date etc difference situations can shine the power of arguments
And with the ability to validate an argument with some criteria,
like the node should be a specific content type

This time, the requirements is pass in date to arguments, example with URL "frontpage/20130320" displaying Mar 20th content
But there is a special requirement limit to prior 7 days only, dates before 7 days will show 403 (individual node access is not restricted)
so I write a custom argument validator:

<?php
//example.module let views knows this module implement some views api:
function example_views_api() {
  return array(
   
'api' => 3.0,
   
'path' => drupal_get_path('module', 'example') . '/includes',
  );
}
?>

<?php
//includes/example.views.inc
//MODULENAME.views.inc defines this is a custom argument validator
function exmaple_views_plugins() {
  return array(
   
'argument validator' => array(
     
'days_limit' => array(
       
'title' => t('7 days limit'),
       
'handler' => 'example_plugin_argument_validate_7_days_limit',
       
'path' => drupal_get_path('module', 'example') . '/includes',
      ),
    ),
  );
}
?>

handler exists inside its own file, so need to define the file in example.info:

files[] = includes/example_plugin_argument_validate_7_days_limit.inc

Implementation:

<?php
//example_plugin_argument_validate_7_days_limit.inc
class example_plugin_argument_validate_7_days_limit extends views_plugin_argument_validate {

  function
construct() {
   
parent::construct();
  }

  function
validate_argument($argument) {
    global
$user;

    if (
in_array('administrator', $user->roles)) {
      return
TRUE;
    }

    if(
is_numeric($argument)) {
     
// as the argument is in form of CCYYMMDD, validate it should be no more than 7 days ago
     
$date = strtotime($argument);
     
$days_ago = strtotime("-7 day");
      if(
$days_ago < $date) {
        return
TRUE;
      }
    }
    return
FALSE;
  }
}
?>
AttachmentSize
Image icon views_plugin_argument_validate.png19.16 KB

Pages

Google