Παράκαμψη προς το κυρίως περιεχόμενο

Renaming / Re-using Drupal modules

So, you have already build a cool module that does a whole bunch of cool stuff. This module has been deployed in production, for a specific customer of yours, and the naming convention of the module follows a pattern related to that specific customer. For example, let's suppose that you have named the module "foo".

Now, you want the functionality that this module provides in a different project. The problem, though, is that you cannot use the same name. You have to change it. You want to name it "bar".

Pretty easy, right? Rename the folder, the ".info" file, the ".module" file and a couple of cases where "Foo" or "foo" can be found within them.

What happens, thought, if your module tree looks like this?

├── css
│   ├── foo-admin.advanced_help.css
│   ├── foo-admin.theme.css
│   ├── foo-admin.theme-rtl.css
│   ├── foo.css
│   ├── foo-rtl.css
│   └── ie
│       └── foo-admin.ie7.css
├── drush
│   └── foo.drush.inc
├── foo.api.php
├── foo_export
│   └── foo_export.module
├── foo.info
├── foo.install
├── foo.module
├── foo.tokens.inc
├── foo_ui.info
├── foo_ui.module
├── handlers
│   ├── foo_handler_area.inc
│   ├── foo_handler_sort_date.inc
│   ├── foo_handler_sort_group_by_numeric.inc
│   ├── foo_handler_sort.inc
│   ├── foo_handler_sort_menu_hierarchy.inc
│   └── foo_handler_sort_random.inc
├── help
│   ├── foo-header.html
│   ├── images
│   │   ├── foo1-admin-large.png
│   │   ├── foo1-admin.png
│   │   ├── foo1-changeviewtype-large.png
│   │   ├── foo1-changeviewtype.png
│   │   ├── foo2-addaview-large.png
│   │   ├── foo2-addaview.png
│   │   ├── foo2-adddisplay-large.png
│   │   ├── foo2-adddisplay.png
│   │   ├── foo2-addfieldsajax-large.png
│   │   ├── foo2-addfieldsajax.png
│   │   ├── foo2-addfields-large.png
│   │   ├── foo2-addfields.png
│   │   ├── foo2-admin-large.png
│   │   ├── foo2-admin.png
│   │   ├── foo2-changedisplaystyle-large.png
│   │   ├── foo2-changedisplaystyle.png
│   │   ├── foo2-fieldspreview-large.png
│   │   ├── foo2-fieldspreview.png
│   │   ├── foo2-newview-large.png
│   │   ├── foo2-newview.png
│   │   ├── foo2-rearrangefields-large.png
│   │   ├── foo2-rearrangefields.png
│   │   ├── foo2-tablestyle-large.png
│   │   ├── foo2-tablestyle.png
│   │   ├── foo3-foo-all.png
│   │   ├── foo3-group-aggregation.png
│   │   ├── foo3-group-aggregation-types.png
│   │   ├── foo3-jump-style-menu.png
│   │   ├── foo3-semanticfoo.png
├── js
│   ├── foo-admin.js
│   ├── foo-contextual.js
│   ├── foo-list.js
├── modules
│   ├── aggregator
│   │   ├── foo_handler_argument_aggregator_category_cid.inc
│   │   ├── foo_handler_argument_aggregator_fid.inc
│   │   ├── foo_handler_argument_aggregator_iid.inc
│   │   ├── foo_handler_field_aggregator_category.inc
│   │   ├── foo_handler_field_aggregator_title_link.inc
│   │   ├── foo_handler_field_aggregator_xss.inc
│   │   ├── foo_handler_filter_aggregator_category_cid.inc
│   │   └── foo_plugin_row_aggregator_rss.inc
│   ├── aggregator.foo.inc
│   ├── book
│   │   └── foo_plugin_argument_default_book_root.inc
│   ├── book.foo.inc
│   ├── comment
│   │   ├── foo_handler_argument_comment_user_uid.inc
│   │   ├── foo_handler_field_comment_depth.inc
│   │   ├── foo_handler_field_comment.inc
│   │   ├── foo_plugin_row_comment_rss.inc
│   │   └── foo_plugin_row_comment_view.inc
│   ├── comment.foo_default.inc
│   ├── comment.foo.inc
│   ├── contact
│   │   └── foo_handler_field_contact_link.inc
│   ├── contact.foo.inc
│   ├── field
│   │   ├── foo_handler_argument_field_list.inc
│   │   ├── foo_handler_argument_field_list_string.inc
│   │   ├── foo_handler_field_field.inc
│   │   ├── foo_handler_filter_field_list_boolean.inc
│   │   ├── foo_handler_filter_field_list.inc
│   │   └── foo_handler_relationship_entity_reverse.inc
│   ├── field.foo.inc
│   ├── file.foo.inc
│   ├── filter
│   │   └── foo_handler_field_filter_format_name.inc
│   ├── filter.foo.inc
│   ├── foo.foo.inc
│   ├── image.foo.inc
│   ├── locale
│   │   ├── foo_handler_argument_locale_group.inc
│   │   ├── foo_handler_argument_locale_language.inc
│   │   ├── foo_handler_field_locale_group.inc
│   │   ├── foo_handler_field_locale_language.inc
│   │   └── foo_handler_sort_node_language.inc
│   ├── locale.foo.inc
│   ├── node
│   │   ├── foo_handler_argument_dates_various.inc
│   │   ├── foo_plugin_argument_default_node.inc
│   │   ├── foo_plugin_argument_validate_node.inc
│   │   ├── foo_plugin_row_node_rss.inc
│   │   └── foo_plugin_row_node_view.inc
│   ├── node.foo_default.inc
│   ├── node.foo.inc
│   ├── node.foo_template.inc
│   ├── poll.foo.inc
│   ├── profile
│   │   ├── foo_handler_field_profile_date.inc
│   │   ├── foo_handler_field_profile_list.inc
│   │   └── foo_handler_filter_profile_selection.inc
│   ├── profile.foo.inc
│   ├── search
│   │   ├── foo_handler_argument_search.inc
│   │   ├── foo_handler_filter_search.inc
│   │   ├── foo_handler_sort_search_score.inc
│   │   └── foo_plugin_row_search_view.inc
│   ├── search.foo_default.inc
│   ├── search.foo.inc
│   ├── statistics
│   │   ├── foo_handler_field_accesslog_path.inc
│   │   ├── foo_handler_field_node_counter_timestamp.inc
│   │   └── foo_handler_field_statistics_numeric.inc
│   ├── statistics.foo_default.inc
│   ├── statistics.foo.inc
│   ├── system
│   │   ├── foo_handler_argument_file_fid.inc
│   │   ├── foo_handler_field_file_extension.inc
│   │   ├── foo_handler_field_file_filemime.inc
│   │   ├── foo_handler_filter_file_status.inc
│   │   └── foo_handler_filter_system_type.inc
│   ├── system.foo.inc
│   ├── taxonomy
│   │   ├── foo_handler_argument_taxonomy.inc
│   │   ├── foo_handler_argument_vocabulary_vid.inc
│   │   ├── foo_plugin_argument_default_taxonomy_tid.inc
│   │   └── foo_plugin_argument_validate_taxonomy_term.inc
│   ├── taxonomy.foo_default.inc
│   ├── taxonomy.foo.inc
│   ├── tracker
│   │   ├── foo_handler_argument_tracker_comment_user_uid.inc
│   │   ├── foo_handler_filter_tracker_boolean_operator.inc
│   │   └── foo_handler_filter_tracker_comment_user_uid.inc
│   ├── tracker.foo.inc
│   ├── translation
│   │   ├── foo_handler_argument_node_tnid.inc
│   │   ├── foo_handler_field_node_link_translate.inc
│   │   ├── foo_handler_filter_node_tnid_child.inc
│   │   ├── foo_handler_filter_node_tnid.inc
│   │   └── foo_handler_relationship_translation.inc
│   ├── translation.foo.inc
│   ├── user
│   │   ├── foo_handler_argument_users_roles_rid.inc
│   │   ├── foo_handler_argument_user_uid.inc
│   │   ├── foo_plugin_argument_validate_user.inc
│   │   └── foo_plugin_row_user_view.inc
│   └── user.foo.inc
├── plugins
│   ├── export_ui
│   │   ├── foo_ui.class.php
│   │   └── foo_ui.inc
│   ├── foo_plugin_access.inc
│   ├── foo_plugin_argument_default_raw.inc
│   ├── foo_plugin_style_summary_unformatted.inc
│   ├── foo_plugin_style_table.inc
│   └── foo_wizard
│       ├── foo_ui_file_managed_foo_wizard.class.php
│       ├── foo_ui_node_foo_wizard.class.php
│       ├── foo_ui_node_revision_foo_wizard.class.php
│       ├── foo_ui_taxonomy_term_foo_wizard.class.php
│       ├── foo_ui_users_foo_wizard.class.php
├── tests
│   ├── comment
│   │   ├── foo_handler_argument_comment_user_uid.test
│   │   └── foo_handler_filter_comment_user_uid.test
│   ├── field
│   │   └── foo_fieldapi.test
│   ├── foo_access.test
│   ├── foo_upgrade.test
│   ├── foo_view.test
│   ├── handlers
│   │   ├── foo_handler_area_text.test
│   │   ├── foo_handler_argument_null.test
│   │   ├── foo_handler_argument_string.test
│   ├── node
│   │   └── foo_node_revision_relations.test
│   ├── plugins
│   │   └── foo_plugin_display.test
│   ├── styles
│   │   ├── foo_plugin_style_base.test
│   │   ├── foo_plugin_style_jump_menu.test
│   │   ├── foo_plugin_style_mapping.test
│   │   ├── foo_plugin_style.test
│   │   └── foo_plugin_style_unformatted.test
│   ├── taxonomy
│   │   └── foo_handler_relationship_node_term_data.test
│   ├── test_handlers
│   │   └── foo_test_area_access.inc
│   ├── test_plugins
│   │   ├── foo_test_plugin_access_test_dynamic.inc
│   │   ├── foo_test_plugin_access_test_static.inc
│   │   └── foo_test_plugin_style_test_mapping.inc
│   └── user
│       ├── foo_handler_field_user_name.test
│       ├── foo_user_argument_default.test
│       ├── foo_user_argument_validate.test
│       └── foo_user.test
├── test_templates
│   ├── foo-view--frontpage.tpl.php
└── theme
    ├── foo-view-list.tpl.php
    ├── foo-view-row-comment.tpl.php
    ├── foo-view-row-rss.tpl.php
    ├── foo-view-unformatted.tpl.php

Well, then, you run the following command in your terminal (just fill in the "path", "old_name" and "new_name" variables):

path="/path/to/folder/foo/"; \
old_name="foo"; \
new_name="bar"; \
new_path=$(echo "$path" | sed "s/$old_name/$new_name/g") \
old_name_upper="$(tr '[:lower:]' '[:upper:]' <<< ${old_name:0:1})${old_name:1}"; \
new_name_upper="$(tr '[:lower:]' '[:upper:]' <<< ${new_name:0:1})${new_name:1}"; \
find "$path" -name "*$old_name*" -print0 | sort -rz |  while read -d $'\0' f; \
do mv -v "$f" "$(dirname "$f")/$(basename "${f//$old_name/$new_name}")"; \
done; \
find "$new_path" -type f -exec sed -i "s/$old_name/$new_name/g; \
s/$old_name_upper/$new_name_upper/g" "{}" \+;

Holler at me if you need help.

Ετικέτες