SlideShare a Scribd company logo
Batch Scripting with Drupal
(Featuring the EntityFieldQuery API)
Engr.Ranel O.Padon
DrupalCamp Manila 2014
ranel.padon@gmail.com | https://github.com/ranelpadon
About Me
Full-time Drupal developer for CNN Travel
Part-time Python lecturer.
Involved in computational Java and Python projects before.
Plays competitive football and futsal.
TOPICS
Why do batch scripting?
How to leverage Entities and the EntityFieldQuery API.
How to implement a batch module?
Sample Actual Use Cases
Why do batching?
There are things that are hard to teach to robots:
spatial awareness and image interpretation.
But there are things that machines could do and easily beat humans:
doing repetitive tasks.
In Drupal, you don't want your site editors to do repetitive tasks:
e.g. updating a field to the same value.
Why do batching?
Avoids PHP Timeout
For implementating intsallation profiles
Why do batching?
Batch processing is execution of a series of programs on a
computer without manual intervention.
Designed to integrate nicely with the Form API, but can also be used
by non-Form API scripts.
Why do batching?
Avoids PHP Timeout (max_execution_time errors)
For long and complex data processing
You can give the admins real-time feedback or summary of results.
When to do batching?
Implementing installation profiles
Used by Drupal's install.php and update.php
Updating the value of a field for all Event nodes.
Deleting all nodes older than 3 years.
Migrating Column nodes to Column taxonomy terms.
Creating custom nodes upon saving a content with an uploaded Excel file,
Batch API is triggered by hook_node_presave() and
goes through each row of the attached Excel file.
The Rise of Entities
“Oh no, I left my stuff in our house.”
Stuff, just like entities, are useful abstraction.
They could change meaning depending on the context.
The Rise of Entities
In Physics, you could treat each object under study as particles.
In Drupal, they are called entities.
Facilitates a unified way to work
with different data units
Concept simplification contributes
to better modularity,flexibility and maintainability.
http://evolvingweb.ca/story/understanding-entity-api-module
The Rise of Entities
Before D7, users and comments didn't have the same power
that nodes (content) had.
no translations, fields, versioning, and so on.
Views (relies on fields) didn’t work with comments and users.
The Rise of Entities
Field is a reusable piece of content. Each field is a primitive data type,
with custom validators and widgets for editing and formatters for display.
Entity Type group together fields (use Entity API for custom ones):
Nodes (content)
Comments
Taxonomy Terms
User Profiles
The Rise of Entities
Bundles are an implementation of an entity type.
They are subtypes of an entity type.
Bundles (subtypes) like articles, events, blog posts, or products could be
generated from node entity. You could add a file download field on
Basic Pages and a subtitle field on Articles.
You could also assign geographic coordinates field to all bundles/entities.
The Rise of Entities
Entity would be one instance of a particular entity type
(specific article or specific user via entity_load()).
Drupal 7 Core provides entity_load(), while the Entity API contrib
module provides entity_save() and entity_delete().
The Rise of Entities
In terms of Object-Oriented Programming:
An entity type is a base class
A bundle is an extended/derived class
A field is a class member,attribute, or property,
An entity is an object or instance of a base or extended class
EntityFieldQuery API
Tool for querying Entities (compared to db_select())
Can query entity properties and fields
Can query field data across entity types:
Fetch all pages and users tagged with taxonomy term “premium”
Returns entity IDs that you could load using entity_load()
Database-agnostic (no issues when migrating from MySQL to PostgreSQL)
EntityFieldQuery API
Fetch all nodes.
EntityFieldQuery API
Fetch all nodes of type “Article”.
EntityFieldQuery API
Fetch all nodes of type “Article”, Published only.
EntityFieldQuery API
Tool for querying Entities
EntityFieldQuery API
Tool for querying Entities
EntityFieldQuery API
Tool for querying Entities
Custom Batch Module
Form API meets Batch API
Custom Batch Module
Batch 12 things, process 5 things at a time
http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
Custom Batch Module
Form Submit trigger
http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
Custom Batch Module
Multiple callback operations and the dynamic $context array (stored in db)
http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
Custom Batch Module
Post Processing
http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
Custom Batch Module
The usual suspects:
mybatch.info
mybatch.module
Then, enable the module in “admin/modules” or using Drush:
$ drush en -y mybatch
Custom Batch Module
Information required in mybatch.module, without a form:
I. URL that will be utilized.
II. Function callback definition for that URL.
Usually contains the setup for the batch process.
III.The batch operation's function definition.
IV.The function definition that will be called after
the batch operation.
Custom Batch Module
1.The batch module URL (http://localhost/admin/mybatch):
Custom Batch Module
1I. Function callback for the URL, setups the batch process.
Custom Batch Module
III. Define the operation callback.
Custom Batch Module
IV.Define the post-operation callback.
Custom Batch Module
Custom Batch Module
III. Define the operation callback (Enhancement).
III. Define the operation callback (Enhancement).
1I. Function callback for the URL (Enhancement).
Custom Batch Module
Information required in mybatch.module, when using a form:
I. URL that will be utilized.
II. Form callback definition for that URL (hook_form).
III. Form Submit definition.
Usually contains the setup for the batch process.
IV.The batch operation's function definition.
V.The function definition that will be called after the batch operation.
Custom Batch Module
Batch API with Form API:
Custom Batch Module
I. URL that will be utilized.
Custom Batch Module
II. Form callback definition for that URL (hook_form).
Custom Batch Module
III. Form Submit definition.
Custom Batch Module
Part IV and V don't need to be changed:
Our Use Case 1
We need to update the Short Bio field text format of User Profiles
from Full HTML to Editorial Filter:
Our Use Case 1
Using our last batch module example module (with form), all parts
except part IV and V will be almost similar.
IV (1/4):
IV (2/4):
IV (3/4):
IV (4/4):
V:
Our Use Case 2
Preview map images for City/Country taxonomy terms with no set
value: (http://travel.cnn.com/malaysia)
Our Use Case 2
Preview map images for City/Country taxonomy terms with no set
value: (http://travel.cnn.com/japan)
Our Use Case 2
Batch API with Form API (Updating the preview images,
part I and part V are almost similar to that of Use Case 1)
II. Form callback definition for that URL (hook_form).
III. Form Submit definition.
IV.Batch operations callback (highlights only)
IV.Batch operations callback (highlights only)
IV.Batch operations callback (highlights only)
IV.Batch operations callback (highlights only)
Summary
Information required in mybatch.module, without a form:
I. URL that will be utilized.
II. Function callback definition for that URL.
Usually contains the setup for the batch process.
III.The batch operation's function definition.
IV.The function definition that will be called after
the batch operation.
Summary
Information required in mybatch.module, when using a form:
I. URL that will be utilized.
II. Form callback definition for that URL (hook_form).
III. Form Submit definition.
Usually contains the setup for the batch process.
IV.The batch operation's function definition.
V.The function definition that will be called after the batch operation.
Summary
Implementing the Batch API without a form could be also
integrated to Drupal hooks or even Drush.
EntityFieldQuery integration to batch operations callback
will facilitate a more readable, flexible, and maintainable
data fetching in the batch process.
Recommended Links
Batch API Docs:
https://drupal.org/node/180528
Examples Module (Batch API):
http://d7.drupalexamples.info/examples/batch_example
Batch API integration with Drush:
http://www.metaltoad.com/blog/using-drupal-batch-api
EntityFieldQuery Docs:
https://drupal.org/node/1343708
EntityFieldQuery as alternative to Views:
http://treehouseagency.com/blog/tim-cosgrove/2012/02/16/entityfieldquery-let-drupal-do-heavy-lifting-pt-1
Long Live Open-Source!

More Related Content

What's hot (18)

00 intro to java
00 intro to java00 intro to java
00 intro to java
Deia Abdullah
 
Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
Java for C++ programers
Java for C++ programersJava for C++ programers
Java for C++ programers
Salahaddin University-Erbil
 
Modular programming
Modular programmingModular programming
Modular programming
Mohanlal Sukhadia University (MLSU)
 
Grade 8: Introduction To Java
Grade 8: Introduction To JavaGrade 8: Introduction To Java
Grade 8: Introduction To Java
nandanrocker
 
Java notes
Java notesJava notes
Java notes
Chaitanya Rajkumar Limmala
 
Java applet
Java appletJava applet
Java applet
Rohan Gajre
 
C++ to java
C++ to javaC++ to java
C++ to java
Ajmal Ak
 
Programming in Java
Programming in JavaProgramming in Java
Programming in Java
Abhilash Nair
 
Introduction of c# day3
Introduction of c# day3Introduction of c# day3
Introduction of c# day3
Arun Kumar Singh
 
Java seminar
Java seminarJava seminar
Java seminar
devendrakhairwa
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
eightbit
 
Java for Recruiters
Java for RecruitersJava for Recruiters
Java for Recruiters
ph7 -
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
Mukesh Tekwani
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
Indrajit Das
 
Core Java
Core JavaCore Java
Core Java
christ university
 
Object oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpObject oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharp
Abefo
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
ThoughtWorks
 

Viewers also liked (20)

Switchable Map APIs with Drupal
Switchable Map APIs with DrupalSwitchable Map APIs with Drupal
Switchable Map APIs with Drupal
Ranel Padon
 
Python Programming - XII. File Processing
Python Programming - XII. File ProcessingPython Programming - XII. File Processing
Python Programming - XII. File Processing
Ranel Padon
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputation
Ranel Padon
 
Operating System Presentation
Operating System PresentationOperating System Presentation
Operating System Presentation
Sajid Khan
 
Manual clips
Manual clipsManual clips
Manual clips
workhome
 
デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。
Chachamaru
 
Introdução a python módulo c
Introdução a python   módulo cIntrodução a python   módulo c
Introdução a python módulo c
Jader Gabriel
 
Import python
Import pythonImport python
Import python
josenildoaf
 
Mba
MbaMba
Mba
KCC Software Ltd. & Easylearning.guru
 
Python IDE Roundup
Python IDE RoundupPython IDE Roundup
Python IDE Roundup
christophfricke
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
Pippi Labradoodle
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon
 
Py S60
Py S60Py S60
Py S60
Jonh Edson
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
Ranel Padon
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
Mustafa Ugur Oduncu
 
Understanding operating systems 5th ed ch04
Understanding operating systems 5th ed ch04Understanding operating systems 5th ed ch04
Understanding operating systems 5th ed ch04
BarrBoy
 
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular Expressions
Ranel Padon
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and Polymorphism
Ranel Padon
 
Introducción a dr racket
Introducción a dr racketIntroducción a dr racket
Introducción a dr racket
Jose Hernandez Moya
 
Power and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQueryPower and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQuery
Ranel Padon
 
Switchable Map APIs with Drupal
Switchable Map APIs with DrupalSwitchable Map APIs with Drupal
Switchable Map APIs with Drupal
Ranel Padon
 
Python Programming - XII. File Processing
Python Programming - XII. File ProcessingPython Programming - XII. File Processing
Python Programming - XII. File Processing
Ranel Padon
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputation
Ranel Padon
 
Operating System Presentation
Operating System PresentationOperating System Presentation
Operating System Presentation
Sajid Khan
 
Manual clips
Manual clipsManual clips
Manual clips
workhome
 
デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。
Chachamaru
 
Introdução a python módulo c
Introdução a python   módulo cIntrodução a python   módulo c
Introdução a python módulo c
Jader Gabriel
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
Pippi Labradoodle
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
Ranel Padon
 
Understanding operating systems 5th ed ch04
Understanding operating systems 5th ed ch04Understanding operating systems 5th ed ch04
Understanding operating systems 5th ed ch04
BarrBoy
 
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular Expressions
Ranel Padon
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and Polymorphism
Ranel Padon
 
Power and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQueryPower and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQuery
Ranel Padon
 
Ad

Similar to Batch Scripting with Drupal (Featuring the EntityFieldQuery API) (20)

Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
均民 戴
 
Entity api
Entity apiEntity api
Entity api
Bishant Shrestha
 
Better Drupal 8 Batch Services
Better Drupal 8 Batch ServicesBetter Drupal 8 Batch Services
Better Drupal 8 Batch Services
Aaron Crosman
 
ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity api
DrupalCamp Kyiv Рысь
 
Understanding the Entity API Module
Understanding the Entity API ModuleUnderstanding the Entity API Module
Understanding the Entity API Module
Sergiu Savva
 
Drupalize your data use entities
Drupalize your data use entitiesDrupalize your data use entities
Drupalize your data use entities
均民 戴
 
What's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field APIWhat's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field API
Drupalize.Me
 
Drupal 7 field API
Drupal 7 field APIDrupal 7 field API
Drupal 7 field API
Karoly Negyesi
 
Linked Data Publishing with Drupal (SWIB13 workshop)
Linked Data Publishing with Drupal (SWIB13 workshop)Linked Data Publishing with Drupal (SWIB13 workshop)
Linked Data Publishing with Drupal (SWIB13 workshop)
Joachim Neubert
 
Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!
tedbow
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
DrupalCamp Kyiv
 
Entity Query API
Entity Query APIEntity Query API
Entity Query API
marcingy
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
Hai Vo Hoang
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7
Zsolt Tasnadi
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Talking to Web Services
Talking to Web ServicesTalking to Web Services
Talking to Web Services
DrupalcampAtlanta2012
 
Drupal course - batch API
Drupal course - batch APIDrupal course - batch API
Drupal course - batch API
Dániel Kalmár
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
drubb
 
Ramp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache SolrRamp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache Solr
lucenerevolution
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
均民 戴
 
Better Drupal 8 Batch Services
Better Drupal 8 Batch ServicesBetter Drupal 8 Batch Services
Better Drupal 8 Batch Services
Aaron Crosman
 
ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity api
DrupalCamp Kyiv Рысь
 
Understanding the Entity API Module
Understanding the Entity API ModuleUnderstanding the Entity API Module
Understanding the Entity API Module
Sergiu Savva
 
Drupalize your data use entities
Drupalize your data use entitiesDrupalize your data use entities
Drupalize your data use entities
均民 戴
 
What's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field APIWhat's New in Drupal 8: Entity Field API
What's New in Drupal 8: Entity Field API
Drupalize.Me
 
Linked Data Publishing with Drupal (SWIB13 workshop)
Linked Data Publishing with Drupal (SWIB13 workshop)Linked Data Publishing with Drupal (SWIB13 workshop)
Linked Data Publishing with Drupal (SWIB13 workshop)
Joachim Neubert
 
Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!
tedbow
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
DrupalCamp Kyiv
 
Entity Query API
Entity Query APIEntity Query API
Entity Query API
marcingy
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
Hai Vo Hoang
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7
Zsolt Tasnadi
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Drupal course - batch API
Drupal course - batch APIDrupal course - batch API
Drupal course - batch API
Dániel Kalmár
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
drubb
 
Ramp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache SolrRamp Up Your Web Experiences Using Drupal and Apache Solr
Ramp Up Your Web Experiences Using Drupal and Apache Solr
lucenerevolution
 
Ad

More from Ranel Padon (10)

CKEditor Widgets with Drupal
CKEditor Widgets with DrupalCKEditor Widgets with Drupal
CKEditor Widgets with Drupal
Ranel Padon
 
Views Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views Module
Ranel Padon
 
Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
Ranel Padon
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
Ranel Padon
 
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Ranel Padon
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
Ranel Padon
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Ranel Padon
 
Web Mapping with Drupal
Web Mapping with DrupalWeb Mapping with Drupal
Web Mapping with Drupal
Ranel Padon
 
CKEditor Widgets with Drupal
CKEditor Widgets with DrupalCKEditor Widgets with Drupal
CKEditor Widgets with Drupal
Ranel Padon
 
Views Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views Module
Ranel Padon
 
Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
Ranel Padon
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
Ranel Padon
 
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Ranel Padon
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
Ranel Padon
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Ranel Padon
 
Web Mapping with Drupal
Web Mapping with DrupalWeb Mapping with Drupal
Web Mapping with Drupal
Ranel Padon
 

Recently uploaded (20)

Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 

Batch Scripting with Drupal (Featuring the EntityFieldQuery API)

  • 1. Batch Scripting with Drupal (Featuring the EntityFieldQuery API) Engr.Ranel O.Padon DrupalCamp Manila 2014 [email protected] | https://github.com/ranelpadon
  • 2. About Me Full-time Drupal developer for CNN Travel Part-time Python lecturer. Involved in computational Java and Python projects before. Plays competitive football and futsal.
  • 3. TOPICS Why do batch scripting? How to leverage Entities and the EntityFieldQuery API. How to implement a batch module? Sample Actual Use Cases
  • 4. Why do batching? There are things that are hard to teach to robots: spatial awareness and image interpretation. But there are things that machines could do and easily beat humans: doing repetitive tasks. In Drupal, you don't want your site editors to do repetitive tasks: e.g. updating a field to the same value.
  • 5. Why do batching? Avoids PHP Timeout For implementating intsallation profiles
  • 6. Why do batching? Batch processing is execution of a series of programs on a computer without manual intervention. Designed to integrate nicely with the Form API, but can also be used by non-Form API scripts.
  • 7. Why do batching? Avoids PHP Timeout (max_execution_time errors) For long and complex data processing You can give the admins real-time feedback or summary of results.
  • 8. When to do batching? Implementing installation profiles Used by Drupal's install.php and update.php Updating the value of a field for all Event nodes. Deleting all nodes older than 3 years. Migrating Column nodes to Column taxonomy terms. Creating custom nodes upon saving a content with an uploaded Excel file, Batch API is triggered by hook_node_presave() and goes through each row of the attached Excel file.
  • 9. The Rise of Entities “Oh no, I left my stuff in our house.” Stuff, just like entities, are useful abstraction. They could change meaning depending on the context.
  • 10. The Rise of Entities In Physics, you could treat each object under study as particles. In Drupal, they are called entities. Facilitates a unified way to work with different data units Concept simplification contributes to better modularity,flexibility and maintainability. http://evolvingweb.ca/story/understanding-entity-api-module
  • 11. The Rise of Entities Before D7, users and comments didn't have the same power that nodes (content) had. no translations, fields, versioning, and so on. Views (relies on fields) didn’t work with comments and users.
  • 12. The Rise of Entities Field is a reusable piece of content. Each field is a primitive data type, with custom validators and widgets for editing and formatters for display. Entity Type group together fields (use Entity API for custom ones): Nodes (content) Comments Taxonomy Terms User Profiles
  • 13. The Rise of Entities Bundles are an implementation of an entity type. They are subtypes of an entity type. Bundles (subtypes) like articles, events, blog posts, or products could be generated from node entity. You could add a file download field on Basic Pages and a subtitle field on Articles. You could also assign geographic coordinates field to all bundles/entities.
  • 14. The Rise of Entities Entity would be one instance of a particular entity type (specific article or specific user via entity_load()). Drupal 7 Core provides entity_load(), while the Entity API contrib module provides entity_save() and entity_delete().
  • 15. The Rise of Entities In terms of Object-Oriented Programming: An entity type is a base class A bundle is an extended/derived class A field is a class member,attribute, or property, An entity is an object or instance of a base or extended class
  • 16. EntityFieldQuery API Tool for querying Entities (compared to db_select()) Can query entity properties and fields Can query field data across entity types: Fetch all pages and users tagged with taxonomy term “premium” Returns entity IDs that you could load using entity_load() Database-agnostic (no issues when migrating from MySQL to PostgreSQL)
  • 18. EntityFieldQuery API Fetch all nodes of type “Article”.
  • 19. EntityFieldQuery API Fetch all nodes of type “Article”, Published only.
  • 20. EntityFieldQuery API Tool for querying Entities
  • 21. EntityFieldQuery API Tool for querying Entities
  • 22. EntityFieldQuery API Tool for querying Entities
  • 23. Custom Batch Module Form API meets Batch API
  • 24. Custom Batch Module Batch 12 things, process 5 things at a time http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
  • 25. Custom Batch Module Form Submit trigger http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
  • 26. Custom Batch Module Multiple callback operations and the dynamic $context array (stored in db) http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
  • 27. Custom Batch Module Post Processing http://www.ent.iastate.edu/it/Batch_and_Queue.pdf
  • 28. Custom Batch Module The usual suspects: mybatch.info mybatch.module Then, enable the module in “admin/modules” or using Drush: $ drush en -y mybatch
  • 29. Custom Batch Module Information required in mybatch.module, without a form: I. URL that will be utilized. II. Function callback definition for that URL. Usually contains the setup for the batch process. III.The batch operation's function definition. IV.The function definition that will be called after the batch operation.
  • 30. Custom Batch Module 1.The batch module URL (http://localhost/admin/mybatch):
  • 31. Custom Batch Module 1I. Function callback for the URL, setups the batch process.
  • 32. Custom Batch Module III. Define the operation callback.
  • 33. Custom Batch Module IV.Define the post-operation callback.
  • 35. Custom Batch Module III. Define the operation callback (Enhancement).
  • 36. III. Define the operation callback (Enhancement).
  • 37. 1I. Function callback for the URL (Enhancement).
  • 38. Custom Batch Module Information required in mybatch.module, when using a form: I. URL that will be utilized. II. Form callback definition for that URL (hook_form). III. Form Submit definition. Usually contains the setup for the batch process. IV.The batch operation's function definition. V.The function definition that will be called after the batch operation.
  • 39. Custom Batch Module Batch API with Form API:
  • 40. Custom Batch Module I. URL that will be utilized.
  • 41. Custom Batch Module II. Form callback definition for that URL (hook_form).
  • 42. Custom Batch Module III. Form Submit definition.
  • 43. Custom Batch Module Part IV and V don't need to be changed:
  • 44. Our Use Case 1 We need to update the Short Bio field text format of User Profiles from Full HTML to Editorial Filter:
  • 45. Our Use Case 1 Using our last batch module example module (with form), all parts except part IV and V will be almost similar.
  • 50. V:
  • 51. Our Use Case 2 Preview map images for City/Country taxonomy terms with no set value: (http://travel.cnn.com/malaysia)
  • 52. Our Use Case 2 Preview map images for City/Country taxonomy terms with no set value: (http://travel.cnn.com/japan)
  • 53. Our Use Case 2 Batch API with Form API (Updating the preview images, part I and part V are almost similar to that of Use Case 1)
  • 54. II. Form callback definition for that URL (hook_form).
  • 55. III. Form Submit definition.
  • 56. IV.Batch operations callback (highlights only)
  • 57. IV.Batch operations callback (highlights only)
  • 58. IV.Batch operations callback (highlights only)
  • 59. IV.Batch operations callback (highlights only)
  • 60. Summary Information required in mybatch.module, without a form: I. URL that will be utilized. II. Function callback definition for that URL. Usually contains the setup for the batch process. III.The batch operation's function definition. IV.The function definition that will be called after the batch operation.
  • 61. Summary Information required in mybatch.module, when using a form: I. URL that will be utilized. II. Form callback definition for that URL (hook_form). III. Form Submit definition. Usually contains the setup for the batch process. IV.The batch operation's function definition. V.The function definition that will be called after the batch operation.
  • 62. Summary Implementing the Batch API without a form could be also integrated to Drupal hooks or even Drush. EntityFieldQuery integration to batch operations callback will facilitate a more readable, flexible, and maintainable data fetching in the batch process.
  • 63. Recommended Links Batch API Docs: https://drupal.org/node/180528 Examples Module (Batch API): http://d7.drupalexamples.info/examples/batch_example Batch API integration with Drush: http://www.metaltoad.com/blog/using-drupal-batch-api EntityFieldQuery Docs: https://drupal.org/node/1343708 EntityFieldQuery as alternative to Views: http://treehouseagency.com/blog/tim-cosgrove/2012/02/16/entityfieldquery-let-drupal-do-heavy-lifting-pt-1