1

I try to make a custom command called findpath based on instructions found there (http://www.freelock.com/comment/1965#comment-1965) When I execute my script, I have an error :

Command findpath needs the following module(s) enabled to run: . [12.98 sec, 33.73 MB] [error]

I can't see where is the problem as i don't even know which module should be enabled.

My drupal version : 7.31

Drush 7.x.5.9

I have many other modules installed but all seem to work perfectly.

This error occurs every time I launch my command.

Thanks for your help

Here are the messages I have :

D:\www\monSite>drush cc all
'all' cache was cleared in D:\www\monSite#default [success]

D:\www\monSite>drush findpath --verbose sites/default/files/upload --debug
Bootstrap to phase 0. [0.55 sec, 3.45 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.6 sec, 3.65 MB] [bootstrap]
Cache MISS cid: 5.9-commandfiles-0-11c341785bfd2d9e3ec5fc07a41dbd3a [2.43 sec, 3.66 MB] [debug]
Cache SET cid: 5.9-commandfiles-0-11c341785bfd2d9e3ec5fc07a41dbd3a [2.51 sec, 3.66 MB] [debug]
Bootstrap to phase 0. [2.68 sec, 7.55 MB] [bootstrap]
Bootstrap to phase 5. [2.75 sec, 7.55 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [2.77 sec, 7.55 MB] [bootstrap]
Initialized Drupal 7.31 root directory at C:/Mes Documents/ReNo/WebRoot/taijiquan [3.34 sec, 9.01 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [3.44 sec, 9.01 MB] [bootstrap]
Initialized Drupal site default at sites/default [3.44 sec, 9.01 MB] [notice]
Cache MISS cid: 5.9-commandfiles-2-c32acd775c18a90c5b41d0fc9accf5ab [3.62 sec, 9.01 MB] [debug]
Cache SET cid: 5.9-commandfiles-2-c32acd775c18a90c5b41d0fc9accf5ab [3.95 sec, 9.02 MB] [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [3.96 sec, 9.01 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [4.02 sec, 9.02 MB] [bootstrap]
Successfully connected to the Drupal database. [4.02 sec, 9.02 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [4.06 sec, 9.68 MB] [bootstrap]
Cache MISS cid: 5.9-commandfiles-5-d643476a6db7b83e0cc3b5363e547c36 [5.62 sec, 33 MB] [debug]
Cache SET cid: 5.9-commandfiles-5-d643476a6db7b83e0cc3b5363e547c36 [9.43 sec, 33 MB] [debug]
Cache MISS cid: 5.9-commandfiles-2-1c82782e4f0daa661b06df029df9c6f1 [9.7 sec, 33.69 MB] [debug]
Cache SET cid: 5.9-commandfiles-2-1c82782e4f0daa661b06df029df9c6f1 [12.85 sec, 33.7 MB] [debug]
Command findpath needs the following module(s) enabled to run: . [12.98 sec, 33.73 MB] [error]
The drush command 'findpath sites/default/files/upload' could not be executed. [12.98 sec, 33.73 MB] [error]

Here is my code (which is actually the same as in the link provided higher)

<?php
/**
* Bulk operation to scan your files directory and ensure that every file has a
* corresponding entry in the 'managed files' table.
*
* Without it, you can't re-use files via filefield_sources as promised.
*
* Original D6 by John Locke on 02/23/2010
* From http://www.freelock.com/blog/john-locke/2010-02/using-file-field-imported-files-drupal-drush-rescue
*
* Upgraded to D7 by dman.
* For a less-naive solution to this problem
* (actually scan pages and attach the right files to individual nodes)
* @see (link is external) http://drupal.org/project/file_ownage
*
*
* USAGE:
* Trial run:
* drush --verbose findpath sites/sitename/files
* Real run:
* drush findpath sites/sitename/files true
*
* BACKUP your DB first!
*/
#
/**
* Provide module specific drush commands
*/
function findfiles_drush_command() {
    $items = array();
    $items['findpath'] = array(
        'description' => 'Search filesystem for files by path',
        'arguments' => array(
            'filepath' => 'Name of path to find.',
            'commit' => 'Save results to files table'
        ),
    );
    return $items;
}
#
/**
* Drush command callback
*/
function drush_findfiles_findpath($scandir, $commit = false){
    $ar = file_scan_directory($scandir, '@.*@');
    foreach ($ar as $item){
        $local_filepath = str_replace($scandir . '/', '', $item->uri);
        // Need to think in file wrappers, from the beginning.
        $file = new stdClass();
        $file->fid = NULL;
        // DO NOT USE $item->name as it truncates the suffix.
        // Normally that would be nice but it cripples IMCE!!
        $file->filename = basename($item->uri);
        $file->uri = 'public://' . $local_filepath;
        $file->filemime = file_get_mimetype($file->uri);
        global $user;
        $file->uid = $user->uid;
        $file->status = FILE_STATUS_PERMANENT;
        #
        // Look for file in {file_managed} table.
        drush_log("Checking db for {$file->uri}");
        $result = db_query("SELECT * FROM {file_managed} WHERE uri = :uri", array(':uri' => $file->uri));
        $record = NULL;
        foreach ($result as $record) {
            // Found at least one
            drush_log("Found file: {$file->uri} fid:{$record->fid}");
        }
        #
        if (!$record) {
            drush_log('File not found in the database yet: '. $file->uri);
            #
            if ($commit){
                drush_log('Saving file to database: '.$file->uri);
                // Get file wrapper CRUD to save it for us
                drupal_chmod($file->uri);
                file_save($file);
                // Other modules - specifically filefield_sources -
                // May not play ball unless the file is 'in use' as well.
                // @see (link is external) file_managed_file_validate()
                // @see (link is external) file_usage_list($file);
                // We don't have anything useful to tell it, about previous usage
                // so just say it's managed by 'system'
                file_usage_add($file, 'system', 'file', $file->fid);
            }
        }
    }
}
?> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.