Engine23

Development

Magento - create a cron job, send transactional email

This example is used to send out a reminder email to customers 21 days after a purchase, if they have not reviewed their products. This also is using email templates, which makes it a bit more complicated, otherwise you can just use the good ole php mail function instead. I am using a site called Bloom so all my notes will reflect that file structure.

Command Line - maillog, search mail log, search by day mail log

This is just a list of commands I know I wont remember, so I am putting them here for reference

grep "status=sent" /var/log/maillog | grep "Aug 5" | awk '{print }' | awk -F "=" '{print }' | awk -F "<" '{print }' | awk -F ">" '{print }' | sort | uniq -c | sort -n 
grep "status=sent" /var/log/maillog | grep "Aug 5" | grep "to=<*>" grep "status=sent" /var/log/maillog | grep "Aug 5" | wc -l 
grep "ralbin@abcompany.com" /var/log/maillog | wc -l less /var/log/maillog grep "abc@hotmail.com" /var/log/maillog

Magento - How to get controller name, action name, router name and module name

You can easily get controller name, action name, router name and module name in template file or in any class file. IN TEMPLATE FILES $this->getRequest()can be used in template (phtml) files. Here is the code:

/**
* get Controller name
*/
$this->getRequest()->getControllerName();
/**

Read more

Extract email address from a mail log file

Here is an example on how I extracted email address from a mail log file: $subject = "1 Aug 5 13:26:20 269701-web1 postfix/smtp[20033]: E730B10582C3: to=, relay=gmail-smtp-in.l.google.com[74.125.91.27]:25, delay=1.4, delays=0.02/0.01/0.13/1.3, dsn=2.0.0, status=sent (250 2.0.0 OK 1312568780 fp10si6690298qab.63) 1 Aug 5 13:30:49 269701-web1 postfix/smtp[20753]: F06EF10582C3: to= , relay=mx4.hotmail.com[65.55.92.136]:25, delay=0.28, delays=0.02/0/0.1/0.15, dsn=2.0.0, status=sent (250 <20110805183048.F06EF10582C3@269701-web1.www.bloom.com> Queued mail for delivery) 1 Aug 5 13:34:13 269701-web1 postfix/smtp[20822]: 5121410582C3: to=, relay=mx1.labcorp.iphmx.com[68.232.129.161]:25, delay=0.91, delays=0.01/0/0.42/0.47, dsn=2.0.0, status=sent (250 ok: Message 21101182 accepted) 1 Aug 5 13:34:14 269701-web1 postfix/smtp[20822]: 75C8610582C3: to=, relay=mx2.labcorp.iphmx.com[68.232.129.150]:25, delay=1, delays=0.02/0/0.49/0.54, dsn=2.0.0, status=sent (250 ok: Message 22975937 accepted) 1 Aug 5 13:44:53 269701-web1 postfix/smtp[21625]: 84B5B10582C3: to=, relay=gmail-smtp-in.l.google.com[74.125.91.27]:25, delay=1.7, delays=0.01/0/0.27/1.4, dsn=2.0.0, status=sent (250 2.0.0 OK 1312569893 ef1si6693357qab.35) ";

function extract_emails_from($string){
  preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
  return $matches[0];
}

Read more

Sorting PHP Objects

// sort an object by key

function sort_object_by_key( $obj, $order='' )
{
    $tmp = array();
    // deconstruct the object into an array
    foreach( $obj as $key => $val )
    {
        $tmp[$key] = '';
    }
   // sort the array
    if($order == 'DESC')
    {
        krsort( $tmp );
    }
    else
    {
        ksort( $tmp );
    }        

Read more

Command Line - copy files using rsync

rsync is a software application for Unix and Windows systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally using compression and recursion. In daemon mode, rsync listens on the default TCP port of 873, serving files in the native rsync protocol or via a remote shell such as RSH or SSH. In the latter case, the rsync client executable must be installed on both the local and the remote host. I use rsync a lot specially to backup my important files between two computers, but also to keep my local slackware repository up to date. rsync is great to keep folders and files synchronized between two computers or in the same computer, you can backup all your important data to an external disk using rsync. rsync uses Copy files with rsync From local to remote computer rsync --progress --partial -avz /folder/to/copy/ user@remote.server:/remote/folder This will copy all files in /folder/to/copy/ to /remote/folder in the remote server, the folder copy itself will not be created in the remote computer, and only its contents will be copied, if you want the folder itself to also be created and then its contents copied inside the newly created copy folder, use this command. rsync --progress --partial -avz /folder/to/copy user@remote.server:/remote/folder Note the trailing slash after copy that makes the difference. The rest of options are: progress: will show the percentage of the file copied partial: tells rsync to

Read more

Command Line - tar and gz

Create tape archives and add or extract files. Syntax tar c [ bBeEfFhiklnopPqvwX [ 0-7 ] ] [ block ] [ tarfile ] [ exclude-file ] {-I include-file | -C directory | file | file } tar r [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] {-I include-file | -C directory | file | file } tar t [ BefFhiklnqvX [ 0-7 ] ] [ tarfile ] [ exclude-file ] {-I include-file | file } ... tar u [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] [ tarfile ] file ... tar x [ BefFhiklmnopqvwX [ 0-7 ] ] [ tarfile ] [ exclude-file ] [ file ... ] c Create. Writing begins at the beginning of the tarfile, instead of at the end. r Replace. The named file s are written at the end of the tarfile. A file created with extended headers must be updated with extended headers (see E flag under Function Modifiers). A file created without extended headers cannot be modified with extended headers. t Table of Contents. The names of the specified files are listed each time they occur in the tar file. If no file argument is given, the names of all files in the tarfile are listed. With the v function modifier, additional information for the specified files is displayed. u Update. The named file s are written at the end of the tarfile if they are not already in the tar file, or if they have been modified since last written to that tarfile. An update can be rather slow. A tarfile created on a 5.x system cannot be updated on a 4.x system. A file created with extended headers must be updated with extended headers (see E flag under Function Modifiers). A file created without extended headers cannot be modified with extended headers. x Extract or restore. The named file s are extracted from the tarfile and written to the directory specified in the tarfile, relative to the current directory. Use the relative path names of files and

Read more