Update imagecache presets of drupal6 to image styles of Drupal7.

Source: Internet
Author: User
Tags drupal

Because the imagecache preset in drupal6 has been integrated into the core of drupal7, this solution is proposed by Vladimir, you need to create a PHP file under your drupal root directory and copy the following code to execute this file.


[Php]
<? Php
Define ('drupal _ root', getcwd ());
Require_once
 
DRUPAL_ROOT. '/regiondes/bootstrap. inc ';
Drupal_bootstrap (DRUPAL_BOOTSTRAP_FULL );
//////////////////////////////////////// /////////
Function imagecache_preset_actions ($ preset, $ reset = FALSE ){
$ Actions_cache = array ();

 
$ Result = db_query ('select * FROM {imagecache_action} where presetid = '. $ preset ['presecret']. 'order by West ');
Foreach ($ result as $ row ){
$ Row = (array) $ row;
$ Row ['data'] = unserialize ($ row ['data']);
$ Actions_cache [$ preset ['presecret'] [] = $ row;
}
Return isset (
 
$ Actions_cache [$ preset ['presecret'])? $ Actions_cache [$ preset ['presecret']: array ();
}
//////////////////////////////////////// /////////
//////////////////////////////////////// /////////
 
Function imagecache_presets (){
$ Presets = array ();

 
$ Normal_presets = array ();

 
$ Result = db_query ('select * FROM {imagecache_preset} order by presetname ');

Foreach ($ result as $ preset ){
$ Preset = (array) $ preset;
$ Presets [$ preset ['presecret'] = $ preset;
$ Presets [$ preset ['presecret'] ['actions'] = imagecache_preset_actions ($ preset );
$ Presets [$ preset ['presecret'] ['store'] = 0;

 
// Collect normal preset names so we can skip ults and mark overrides accordingly
$ Normal_presets [$ preset ['presetname'] = $ preset ['presecret'];
}
Return
 
$ Presets;
}
//////////////////////////////////////// /////////
//////////////////////////////////////// /////////
 
$ Styles_cnt = 0;
$ Required ts_new_cnt = 0;
$ Required ts_ext_cnt = 0;
$ Presets = imagecache_presets ();
Foreach ($ presets as $ preset)
{
$ Styles_cnt ++; // inc styles

$ Style = image_style_load ($ preset ['presetname']);

$ Style ['name'] = $ preset ['presetname'];
$ Style = image_style_save ($ style );
If (! Isset ($ style ['effects'])
{
$ Style ['effects'] = array ();
}
Foreach ($ preset ['actions'] as $ action)
{
$ Action ['action'] = str_replace ('imagecache', 'image', $ action ['action']);
$ Action ['module'] = str_replace ('imagecache', 'image', $ action ['module']);

$ Effect_ieid = FALSE; // effect not exists
Foreach ($ style ['effects'] as $ effect)
{
If ($ effect ['name'] = $ action ['action'] &
$ Effect ['module'] = $ action ['module'] &
$ Effect ['weight'] = $ action ['weight'] &
$ Effect ['data'] = $ action ['data'])
{
$ Effect_ieid = $ effect ['ieid']; // effect exists
}
}
$ Effect = array ();
If ($ effect_ieid)
{
$ Effects_ext_cnt ++; // inc exists
$ Effect = image_effect_load ($ effect_ieid, $ style ['name']);
}
Else
{
$ Effects_new_cnt ++; // inc new
$ Effect = image_effect_definition_load ($ action ['action']);
}

$ Effect ['isid'] = $ style ['isid'];

$ Effect ['name'] = $ action ['action'];
$ Effect ['module'] = $ action ['module'];
$ Effect ['weight'] = $ action ['weight'];
$ Effect ['data'] = $ action ['data'];
$ Effect = image_effect_save ($ effect );
$ Style ['effect'] [$ effect ['ieid'] = $ effect;
}
$ Style = image_style_save ($ style );
}
Print
 
"Styles: $ styles_cnt, Effects new: $ effects_new_cnt, Effects exists: $ effects_ext_cnt \ n ";
?>

<? Php
Define ('drupal _ root', getcwd ());
Require_once

DRUPAL_ROOT. '/regiondes/bootstrap. inc ';
Drupal_bootstrap (DRUPAL_BOOTSTRAP_FULL );
//////////////////////////////////////// /////////
Function imagecache_preset_actions ($ preset, $ reset = FALSE ){
$ Actions_cache = array ();

$ Result = db_query ('select * FROM {imagecache_action} where presetid = '. $ preset ['presecret']. 'order by West ');
Foreach ($ result as $ row ){
$ Row = (array) $ row;
$ Row ['data'] = unserialize ($ row ['data']);
$ Actions_cache [$ preset ['presecret'] [] = $ row;
}
Return isset (

$ Actions_cache [$ preset ['presecret'])? $ Actions_cache [$ preset ['presecret']: array ();
}
//////////////////////////////////////// /////////
//////////////////////////////////////// /////////

Function imagecache_presets (){
$ Presets = array ();

$ Normal_presets = array ();

$ Result = db_query ('select * FROM {imagecache_preset} order by presetname ');

Foreach ($ result as $ preset ){
$ Preset = (array) $ preset;
$ Presets [$ preset ['presecret'] = $ preset;
$ Presets [$ preset ['presecret'] ['actions'] = imagecache_preset_actions ($ preset );
$ Presets [$ preset ['presecret'] ['store'] = 0;

// Collect normal preset names so we can skip ults and mark overrides accordingly
$ Normal_presets [$ preset ['presetname'] = $ preset ['presecret'];
}
Return

$ Presets;
}
//////////////////////////////////////// /////////
//////////////////////////////////////// /////////

$ Styles_cnt = 0;
$ Required ts_new_cnt = 0;
$ Required ts_ext_cnt = 0;
$ Presets = imagecache_presets ();
Foreach ($ presets as $ preset)
{
$ Styles_cnt ++; // inc styles

$ Style = image_style_load ($ preset ['presetname']);

$ Style ['name'] = $ preset ['presetname'];
$ Style = image_style_save ($ style );
If (! Isset ($ style ['effects'])
{
$ Style ['effects'] = array ();
}
Foreach ($ preset ['actions'] as $ action)
{
$ Action ['action'] = str_replace ('imagecache', 'image', $ action ['action']);
$ Action ['module'] = str_replace ('imagecache', 'image', $ action ['module']);

$ Effect_ieid = FALSE; // effect not exists
Foreach ($ style ['effects'] as $ effect)
{
If ($ effect ['name'] = $ action ['action'] &
$ Effect ['module'] = $ action ['module'] &
$ Effect ['weight'] = $ action ['weight'] &
$ Effect ['data'] = $ action ['data'])
{
$ Effect_ieid = $ effect ['ieid']; // effect exists
}
}
$ Effect = array ();
If ($ effect_ieid)
{
$ Effects_ext_cnt ++; // inc exists
$ Effect = image_effect_load ($ effect_ieid, $ style ['name']);
}
Else
{
$ Effects_new_cnt ++; // inc new
$ Effect = image_effect_definition_load ($ action ['action']);
}

$ Effect ['isid'] = $ style ['isid'];

$ Effect ['name'] = $ action ['action'];
$ Effect ['module'] = $ action ['module'];
$ Effect ['weight'] = $ action ['weight'];
$ Effect ['data'] = $ action ['data'];
$ Effect = image_effect_save ($ effect );
$ Style ['effect'] [$ effect ['ieid'] = $ effect;
}
$ Style = image_style_save ($ style );
}
Print

"Styles: $ styles_cnt, Effects new: $ effects_new_cnt, Effects exists: $ effects_ext_cnt \ n ";
?> Happy drupalling

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.