eZ Community » Blogs » Benjamin Kroll » eep in action: eZ Publish command...

By

Benjamin Kroll

eep in action: eZ Publish command line operations

Wednesday 23 September 2015 12:13:24 am

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

eep (Ease eZ Publish) is a command line tool we introduced in a previous post, which in combination with other command line tools like awk, grep and xargs makes for powerful one-liners. The examples in this post will highlight its versatility and show just how quickly and conveniently eZ Publish related tasks can be accomplished using eep. Get ready for some command-line fun!

Example 1: Removing objects that are not reverse related to other content objects

In our example Publisher objects that have no reverse relations are useless and can be removed to clean up the content structure and save space.

Check how many 'empty' publisher objects we have

> eep contentclass fetchallinstances onix_publisher | awk '$1 == "|" {print $2}' | xargs -IOID eep co reverserelated OID | grep 'count 0' | wc -l

120
  1. eep contentclass fetchallinstances onix_publisher
    Use eep to fetch all publisher object instances. Pipe output to awk.

  2. awk '$1 == "|" {print $2}'
    Use awk to print lines where the first column equals "|" (prefix for all result rows) and print column 2 (the object ID). Pipe output to xargs.

  3. xargs -IOID eep co reverserelated OID
    Use xargs to call eep's contentobject module's (co) "reverserelated" method for each object ID (OID). Pipe to grep.

  4. grep 'count 0'

    Use grep to select the lines that report empty objects.

Knowing how many unused objects there are is probably only the first step. Next steps might be; deciding if this is an issue that needs resolving or not, figuring out why there are unused objects, or removing them. In the last case, eep is also the way to go since it provides: eep contentobject delete <object id>

Log object IDs for all "empty" publisher objects

Re-using steps 1-4 from the previous 1-liner and adding some filtering:

> eep contentclass fetchallinstances onix_publisher | awk '$1 == "|" {print $2}' | xargs -IOID eep co reverserelated OID | grep 'count 0' | grep -oE '\[([0-9]{1,})\]' | grep -oE '[0-9]{1,}’ > empty_publishers.oids
> cat empty_publishers.oids

133111
135272
140434
...
  1. grep -oE '\[([0-9]{1,})\]'
    Use grep to show only the regular expression matches (o) using extended regular expression syntax (E) e.g.

     [1625]
  2. grep -oE '[0-9]{1,}'
    Using grep again to get the object ID only. Pipe to log file.

    Note: On systems where the -P option (Perl regular expression matching) is available, the second grep call can be avoided as it will return the matched group only.

  3. > empty_publishers.oids
    Pipe publisher object IDs to a log file.

Delete "empty" publishers

> cat empty_publishers.oids | xargs -IOID eep contentobject delete OID > empty_publishers_deleted.log
> empty_publishers_deleted.log | wc -l

120
  1. cat empty_publishers.oids
    Use cat to iterate over the object IDs log file. Pipe to xargs.
  2. xargs -IOID eep contentobject delete OID
    Use xargs to call eep's "contentobject" module's "delete" method for each object ID.
  3. > empty_publishers_deleted.log
    Pipe the delete process results to a log file.
  4. > empty_publishers_deleted.log | wc -l
    Use wc with line count option (-l) to get the total of deleted objects, which should match step 1.

Verify all 'empty' publishers are gone

Repeating the first command we see no empty publishers remain.

> eep contentclass fetchallinstances onix_publisher | awk '$1 == "|" {print $2}' | xargs -IOID eep co reverserelated OID | grep 'count 0' | wc -l

0

We're done!

Note that in many cases, it is often easier to develop the 1-liner by using intermediate output files.

Example 2: Indexing a cross section of content with eep list and eep ezfind

In our example we want to index a small number of book objects from a range of folders (for example, folders named "A" to "Z" that contain books) under a common parent node. Indexing the whole data set would take too long to test something simple locally; so we just index the first 20 objects at the second level in the content tree.

 > eep list children 123 | awk '$1=="|" {print $4}' | xargs -INID eep list children NID --limit=20 | awk '$1=="|" {print $2}' | xargs -IOID eep ezfind indexobject OID
  1. eep list children 123
    List book parent folder's (123) children. Pipe to awk.
  2. awk '$1=="|" {print $4}'
    Get the node ID from the previous result listing (A-Z book folders). Pipe to xargs.
  3. xargs -INID eep list children NID --limit=20
    List 20 children of each of those nodes. Pipe to awk.
  4. awk '$1=="|" {print $2}'
    Get the object ID from each of those children (book objects). Pipe to xargs.
  5. xargs -IOID eep ezfind indexobject OID
    Index each book object via eep ezfind

Example 3: Retrieve node IDs for all blog posts of a specific owner using eep contentclass and eep contentobject

Note: The example below uses the eep module aliases for contentclass (cc) and contentobject (co). Check eep help to see what other aliases are available.

 > eep cc fetchallinstances blog_post | awk '$1=="|" {print $2}' | xargs -IOID eep co info OID | grep -A6 'OwnerID | 1833' | awk '$1=="|" && $2=="MainNodeID" {print $4}'
  1. eep cc fetchallinstances blog_post
    Fetch all instances of blog post objects. Pipe to awk.
  2. awk '$1=="|" {print $2}'
    Get the object ID from the results table. Pipe to xargs
  3. xargs -IOID eep co info OID
    Fetch the blog post object info. Pipe to grep.
  4. grep -A6 'OwnerID | 1833'
    grep lines that match the desired owner ID from the info listing results as well as the next 6 lines after the match (which contain the last piece of information we want). Pipe to awk.
  5. awk '$1=="|" && $2=="MainNodeID" {print $4}'
    Use awk to get the main node ID from the grep match results

The examples we showed in this post should help you to see how eep can make your eZ Publish developer life simpler!

Links

Proudly Developed with from