epub.drush.inc in Epub 8
Contains epub drush commands.
File
drush/epub.drush.incView source
<?php
/**
* @file
* Contains epub drush commands.
*/
/**
* Implements hook_drush_command().
*/
function epub_drush_command() {
$items = array();
$items['epub-flush'] = array(
'description' => dt('Unzip all the epub files.'),
'arguments' => array(
'fid1' => dt('start with this fid'),
'fid2' => dt('stop with this fid'),
),
'examples' => array(
'Flush all files' => 'drush epub-flush',
'Flush file with fid from 5' => 'drush epub-flush 5',
'Flush file with fid between 5-10' => 'drush epub-flush 5 10',
),
);
return $items;
}
/**
* Reset file mime type for epub files.
* @param null $fid1
* @param null $fid2
* @return bool
*/
function drush_epub_flush($fid1 = NULL, $fid2 = NULL) {
$query = db_select('file_managed', 'fid')
->fields('fid', array(
'fid',
));
if (is_numeric($fid1)) {
$query
->condition('fid', $fid1, '>=');
if (is_numeric($fid2)) {
if ($fid2 > $fid1) {
$query
->condition('fid', $fid2, '<=');
}
else {
drush_set_error('Make sure fid1 < fid2.');
return False;
}
}
}
foreach ($query
->execute()
->fetchCol() as $fid) {
$file = file_load($fid);
if (epub_reset_mimetype($file)) {
drush_log(dt('File @fid: mimetype was reset.', array(
'@fid' => $file->fid,
)), 'ok');
}
}
}
Functions
Name | Description |
---|---|
drush_epub_flush | Reset file mime type for epub files. |
epub_drush_command | Implements hook_drush_command(). |