2016-03-22 00:55:18 +01:00
|
|
|
#!/usr/bin/env php -qC
|
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - check namespace usage in converted code
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @copyright 2016 by Ralf Becker <rb@stylite.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (php_sapi_name() !== 'cli') // security precaution: forbit calling as web-page
|
|
|
|
{
|
|
|
|
die('<h1>fix_api.php must NOT be called as web-page --> exiting !!!</h1>');
|
|
|
|
}
|
|
|
|
|
|
|
|
// raw replacements
|
2016-04-27 21:26:13 +02:00
|
|
|
$add_use_api = array(
|
|
|
|
"#use EGroupware\\\\Api;\n#" => '', // remove evtl. use EGroupware\Api, as we add it again below
|
2016-04-29 15:03:04 +02:00
|
|
|
"#<\?php\n+\s*/\*+?(.*)\*/#msU" => "<?php\n/**$1*/\n\nuse EGroupware\\Api;",
|
2016-04-27 21:26:13 +02:00
|
|
|
);
|
|
|
|
$replace = array(
|
2016-03-22 00:55:18 +01:00
|
|
|
'#egw_framework::csp_connect_src_attrs\(#' => "Api\\Header\\ContentSecurityPolicy::add('connect-src', ",
|
|
|
|
'#egw_framework::csp_frame_src_attrs\(#' => "Api\\Header\\ContentSecurityPolicy::add('frame-src', ",
|
|
|
|
'#egw_framework::csp_script_src_attrs\(#' => "Api\\Header\\ContentSecurityPolicy::add('script-src', ",
|
|
|
|
'#egw_framework::csp_style_src_attrs\(#' => "Api\\Header\\ContentSecurityPolicy::add('style-src', ",
|
|
|
|
"#egw_session::appsession\(([^,]+),\s*('[^']+')\)#" => 'Api\\Cache::getSession($2, $1)',
|
|
|
|
"#egw_session::appsession\(([^,]+),\s*('[^']+'),\s*#" => 'Api\\Cache::setSession($2, $1, ',
|
|
|
|
"#\\\$GLOBALS\['egw'\]->session->appsession\(([^,]+),\s*('[^']+')\)#" => 'Api\\Cache::getSession($2, $1)',
|
|
|
|
"#\\\$GLOBALS\['egw'\]->session->appsession\(([^,]+),\s*('[^']+'),\s*#" => 'Api\\Cache::setSession($2, $1, ',
|
|
|
|
"#\\\$GLOBALS\['egw'\]->common->#" => 'common::',
|
2016-04-06 22:04:32 +02:00
|
|
|
"#\\\$GLOBALS\['egw'\]->hooks->#" => 'Api\\Hooks::',
|
2016-04-27 21:26:13 +02:00
|
|
|
'#Api\\\\Hooks::hook_implemented#' => 'Api\\Hooks::implemented',
|
|
|
|
'#Api\\\\Hooks::hook_exists#' => 'Api\\Hooks::exists',
|
2016-04-29 15:03:04 +02:00
|
|
|
'#Api\\\\Hooks::register_(all_hooks|hooks|single_app_hook)\([^)]*\)#' => 'Api\\Hooks::read(true)',
|
2016-04-06 22:04:32 +02:00
|
|
|
"#\\\$GLOBALS\['egw'\]->translation->#" => 'Api\\Translation::',
|
2016-04-29 15:03:04 +02:00
|
|
|
"#\\\$GLOBALS\['egw'\]->country->#" => 'Api\\Country::',
|
2016-04-07 22:42:06 +02:00
|
|
|
'#egw_framework::csp_script_src_attrs\((.*)\);#' => "Api\\Header\\ContentSecurityPolicy::add('script-src', \$1);",
|
|
|
|
'#egw_framework::csp_style_src_attrs\((.*)\);#' => "Api\\Header\\ContentSecurityPolicy::add('style-src', \$1);",
|
|
|
|
'#egw_framework::csp_connect_src_attrs\((.*)\);#' => "Api\\Header\\ContentSecurityPolicy::add('connect-src', \$1);",
|
|
|
|
'#egw_framework::csp_frame_src_attrs\((.*)\);#' => "Api\\Header\\ContentSecurityPolicy::add('frame-src', \$1);",
|
2016-04-26 20:27:51 +02:00
|
|
|
'#common::show_date\(([^,]+),\s*([^,]+),\s*false\)#' => 'Api\\DateTime::to($1, $2)',
|
2016-04-29 15:03:04 +02:00
|
|
|
"#\\\$GLOBALS\['egw'\]->preferences->change#" => '$GLOBALS[\'egw\']->preferences->add',
|
2016-03-22 00:55:18 +01:00
|
|
|
);
|
|
|
|
// enclose class-names and static methods with some syntax check
|
2016-05-03 21:17:44 +02:00
|
|
|
$class_start = '#(?<!function)([\[\s,;().!=])';
|
2016-04-07 22:42:06 +02:00
|
|
|
$class_end = '(::|\\(|\\)|;|\?|:|\\s|,|$)#';
|
2016-03-22 00:55:18 +01:00
|
|
|
foreach(array(
|
|
|
|
'accounts' => 'Api\\Accounts',
|
2016-04-06 22:04:32 +02:00
|
|
|
'acl' => 'Api\\Acl',
|
|
|
|
'EGW_ACL_READ' => 'Api\\Acl::READ',
|
|
|
|
'EGW_ACL_ADD' => 'Api\\Acl::ADD',
|
|
|
|
'EGW_ACL_EDIT' => 'Api\\Acl::EDIT',
|
|
|
|
'EGW_ACL_DELETE' => 'Api\\Acl::DELETE',
|
|
|
|
'EGW_ACL_PRIVATE' => 'Api\\Acl::PRIVAT',
|
|
|
|
'EGW_ACL_GROUP_MANAGERS' => 'Api\\Acl::GROUPMGRS',
|
|
|
|
'EGW_ACL_CUSTOM_1' => 'Api\\Acl::CUSTOM1',
|
|
|
|
'EGW_ACL_CUSTOM_2' => 'Api\\Acl::CUSTOM2',
|
|
|
|
'EGW_ACL_CUSTOM_3' => 'Api\\Acl::CUSTOM3',
|
2016-04-27 21:26:13 +02:00
|
|
|
'applications' => 'Api\\Egw\\Applications',
|
2016-05-09 11:15:48 +02:00
|
|
|
'asyncservice' => 'Api\\Asyncservice',
|
2016-03-22 00:55:18 +01:00
|
|
|
'auth' => 'Api\\Auth',
|
|
|
|
'categories' => 'Api\\Categories',
|
|
|
|
'config::get_customfields' => 'Api\\Storage\\Customfields::get',
|
|
|
|
'config' => 'Api\\Config',
|
2016-04-06 22:04:32 +02:00
|
|
|
'common::setlocale' => 'Api\\Preferences::setlocale',
|
|
|
|
'common::generate_uid' => 'Api\\CalDAV::generate_uid',
|
|
|
|
'common::ldap_addslashes' => 'Api\\Ldap::quote',
|
|
|
|
'common::ldapConnect' => 'Api\\Ldap::factory',
|
2016-03-22 00:55:18 +01:00
|
|
|
'common::egw_exit' => 'exit',
|
2016-04-06 22:04:32 +02:00
|
|
|
'common::randomstring' => 'Api\\Auth::randomstring',
|
|
|
|
'common::display_fullname' => 'Api\\Accounts::format_username',
|
|
|
|
'common::grab_owner_name' => 'Api\\Accounts::username',
|
|
|
|
'common::find_image' => 'Api\\Image::find',
|
|
|
|
'common::image' => 'Api\\Image::find',
|
|
|
|
'common::svg_usable' => 'Api\\Image::svg_usable',
|
|
|
|
'common::image_map' => 'Api\\Image::map',
|
|
|
|
'common::delete_image_map' => 'Api\\Image::invalidate',
|
|
|
|
'common::transliterate' => 'Api\\Translation::to_ascii',
|
|
|
|
'common::email_address' => 'Api\\Accounts::email',
|
|
|
|
'common::next_id' => 'Api\\Accounts\\Ldap::next_id',
|
|
|
|
'common::last_id' => 'Api\\Accounts\\Ldap::last_id',
|
2016-05-14 21:26:36 +02:00
|
|
|
'common::egw_header' => "echo \$GLOBALS['egw']->framework->header",
|
|
|
|
'common::egw_footer' => "echo \$GLOBALS['egw']->framework->footer",
|
2016-04-26 20:27:51 +02:00
|
|
|
'common::show_date' => 'Api\\DateTime::server2user',
|
2016-04-27 21:26:13 +02:00
|
|
|
'common::get_tpl_dir' => 'Api\\Framework\\Template::get_dir',
|
2016-05-04 21:07:54 +02:00
|
|
|
'common::get_referer' => 'Api\\Header\\Referer::get',
|
2016-04-06 22:04:32 +02:00
|
|
|
'country' => 'Api\\Country',
|
2016-04-26 20:27:51 +02:00
|
|
|
'egw' => 'Api\\Egw',
|
|
|
|
'egw_minimal' => 'Api\\Egw\\Base',
|
2016-03-22 00:55:18 +01:00
|
|
|
'egw_cache' => 'Api\\Cache',
|
|
|
|
'egw_ckeditor_config' => 'Api\\Html\\CkEditorConfig',
|
|
|
|
'egw_customfields' => 'Api\\Storage\\Customfields',
|
|
|
|
'egw_db' => 'Api\\Db',
|
|
|
|
'egw_digest_auth' => 'Api\\Header\\Authentication',
|
|
|
|
'egw_exception' => 'Api\\Exception',
|
|
|
|
'egw_exception_no_permission' => 'Api\\Exception\\NoPermission',
|
|
|
|
'egw_exception_no_permission_app' => 'Api\\Exception\\NoPermission\\App',
|
|
|
|
'egw_exception_no_permission_admin' => 'Api\\Exception\\NoPermission\\Admin',
|
|
|
|
'egw_exception_no_permission_record' => 'Api\\Exception\\NoPermission\\Record',
|
|
|
|
'egw_exception_not_found' => 'Api\\Exception\\NotFound',
|
|
|
|
'egw_exception_assertion_failed' => 'Api\\Exception\\AssertionFailed',
|
|
|
|
'egw_exception_wrong_parameter' => 'Api\\Exception\\WrongParameter',
|
|
|
|
'egw_exception_wrong_userinput' => 'Api\\Exception\\WrongUserinput',
|
|
|
|
'egw_exception_db' => 'Api\\Db\\Exception',
|
|
|
|
'egw_exception_db_invalid_sql' => 'Api\\Db\\Exception\\InvalidSql',
|
|
|
|
'egw_exception_redirect' => 'Api\\Exception\\Redirect',
|
2016-04-07 22:42:06 +02:00
|
|
|
'egw_favorites' => 'Api\\Framework\\Favorites',
|
|
|
|
'egw_framework::validate_file' => 'Api\\Framework::includeJS',
|
|
|
|
'egw_framework::favorite_list' => 'Api\\Framework\\Favorites::list_favorites',
|
|
|
|
'egw_framework' => 'Api\\Framework',
|
2016-03-22 00:55:18 +01:00
|
|
|
'egw_json_request' => 'Api\\Json\\Request',
|
|
|
|
'egw_json_response' => 'Api\\Json\\Response',
|
|
|
|
'egw_link' => 'Api\\Link',
|
2016-04-06 22:04:32 +02:00
|
|
|
'egw_mailer' => 'Api\\Mailer',
|
2016-03-22 00:55:18 +01:00
|
|
|
'egw_session' => 'Api\\Session',
|
2016-04-06 22:04:32 +02:00
|
|
|
'egw_tail' => 'Api\\Json\\Tail',
|
2016-03-22 00:55:18 +01:00
|
|
|
'egw_time' => 'Api\\DateTime',
|
|
|
|
'egw_vfs' => 'Api\\Vfs',
|
2016-04-06 22:04:32 +02:00
|
|
|
'groupdav' => 'Api\CalDAV',
|
|
|
|
'groupdav_principal' => 'Api\\CalDAV\\Principal',
|
|
|
|
'groupdav_handler' => 'Api\\CalDAV\\Handler',
|
|
|
|
'egw_ical_iterator' => 'Api\\CalDAV\\IcalIterator',
|
2016-03-22 00:55:18 +01:00
|
|
|
'historylog' => 'Api\\Storage\\History',
|
|
|
|
'html::\$user_agent' => 'Api\\Header\\UserAgent::type()',
|
|
|
|
'html::\$ua_version' => 'Api\\Header\\UserAgent::version()',
|
|
|
|
'html::\$ua_mobile' => 'Api\\Header\\UserAgent::mobile()',
|
|
|
|
'html::safe_content_header' => 'Api\\Header\\Content::safe',
|
|
|
|
'html::content_header' => 'Api\\Header\\Content::type',
|
|
|
|
'html::content_disposition_header' => 'Api\\Header\\Content::disposition',
|
|
|
|
'html' => 'Api\\Html',
|
|
|
|
'iface_stream_wrapper' => 'Api\\Vfs\\StreamWrapperIface',
|
|
|
|
'mime_magic' => 'Api\\MimeMagic',
|
|
|
|
'preferences' => 'Api\\Preferences',
|
|
|
|
'solink' => 'Api\\Link\\Storage',
|
|
|
|
'sqlfs_stream_wrapper' => 'Api\\Vfs\\Sqlfs\\StreamWrapper',
|
|
|
|
'sqlfs_utils' => 'Api\\Vfs\\Sqlfs\\Utils',
|
2016-04-08 09:50:15 +02:00
|
|
|
'Template' => 'Api\\Framework\\Template',
|
2016-04-06 22:04:32 +02:00
|
|
|
'translation::decodeMailHeader' => 'Api\\Mail\\Html::decodeMailHeader',
|
|
|
|
'translation::replaceEmailAdresses' => 'Api\\Mail\\Html::replaceEmailAdresses',
|
|
|
|
'translation::replaceTagsCompletley' => 'Api\\Mail\\Html::replaceTagsCompletley',
|
|
|
|
'translation::transform_mailto2text' => 'Api\\Mail\\Html::transform_mailto2text',
|
|
|
|
'translation::transform_url2text' => 'Api\\Mail\\Html::transform_url2text',
|
|
|
|
'translation::convertHTMLToText' => 'Api\\Mail\\Html::convertHTMLToText',
|
|
|
|
'translation::splithtmlByPRE' => 'Api\\Mail\\Html::splithtmlByPRE',
|
2016-03-22 00:55:18 +01:00
|
|
|
'translation' => 'Api\\Translation',
|
|
|
|
// etemplate2
|
|
|
|
'etemplate_new' => 'Api\\Etemplate',
|
|
|
|
'etemplate_widget' => 'Api\\Etemplate\\Widget',
|
|
|
|
'etemplate_widget_entry' => 'Api\\Etemplate\\Widget\\Entry',
|
|
|
|
'etemplate_widget_tree' => 'Api\\Etemplate\\Widget\\Tree',
|
|
|
|
'etemplate_widget_select' => 'Api\\Etemplate\\Widget\\Select',
|
|
|
|
'etemplate_widget_link' => 'Api\\Etemplate\\Widget\\Link',
|
|
|
|
'etemplate_widget_nextmatch' => 'Api\\Etemplate\\Widget\\Nextmatch',
|
|
|
|
'etemplate_widget_taglist' => 'Api\\Etemplate\\Widget\\Taglist',
|
|
|
|
'etemplate_widget_file' => 'Api\\Etemplate\\Widget\\File',
|
|
|
|
'etemplate_widget_vfs' => 'Api\\Etemplate\\Widget\\Vfs',
|
2016-04-02 21:55:08 +02:00
|
|
|
'etemplate_request' => 'Api\\Etemplate\\Request',
|
2016-03-22 00:55:18 +01:00
|
|
|
'nextmatch_widget::category_action' => 'Api\\Etemplate\\Widget\\Nextmatch::category_action',
|
2016-04-29 15:03:04 +02:00
|
|
|
'nextmatch_widget::DEFAULT_MAX_MENU_LENGTH' => 'Api\\Etemplate\\Widget\\Nextmatch::DEFAULT_MAX_MENU_LENGTH',
|
2016-05-04 21:07:54 +02:00
|
|
|
'customfields_widget::update_customfield_links' => 'Api\Storage\Customfields::update_links',
|
2016-05-03 21:17:44 +02:00
|
|
|
'egw_keymanager' => 'Api\\Etemplate\\KeyManager',
|
2016-05-05 09:23:57 +02:00
|
|
|
'etemplate::array_stripslashes' => 'array_stripslashes',
|
2016-03-22 00:55:18 +01:00
|
|
|
// so_sql and friends
|
|
|
|
'so_sql' => 'Api\\Storage\\Base',
|
|
|
|
'so_sql_cf' => 'Api\\Storage',
|
|
|
|
'so_sql2' => 'Api\\Storage\\Base2',
|
|
|
|
'bo_tracking' => 'Api\\Storage\\Tracking',
|
2016-04-06 22:04:32 +02:00
|
|
|
'bo_merge' => 'Api\\Storage\\Merge',
|
2016-03-22 00:55:18 +01:00
|
|
|
// addressbook backend
|
|
|
|
'addressbook_bo' => 'Api\\Contacts',
|
|
|
|
'addressbook_so' => 'Api\\Contacts\\Storage',
|
2016-05-03 21:17:44 +02:00
|
|
|
'addressbook_merge' => 'Api\\Contacts\\Merge',
|
2016-03-22 00:55:18 +01:00
|
|
|
) as $from => $to)
|
|
|
|
{
|
|
|
|
$replace[$class_start.$from.$class_end] = '$1'.$to.'$2';
|
|
|
|
}
|
2016-04-26 20:27:51 +02:00
|
|
|
// raw expressions running after regular replacements, because they would be replaced themself if running before
|
|
|
|
$replace += array(
|
|
|
|
"#\\\$GLOBALS\['egw'\]->js->#" => 'egw_framework::',
|
|
|
|
);
|
2016-03-22 00:55:18 +01:00
|
|
|
//print_r($replace);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check namespace usage in converted code
|
|
|
|
*
|
|
|
|
* @param string $file filename
|
2016-04-07 22:42:06 +02:00
|
|
|
* @param boolean $dry_run =false true: only echo fixed file, not fix it
|
2016-03-22 00:55:18 +01:00
|
|
|
* @return boolean false on error
|
|
|
|
*/
|
2016-04-07 22:42:06 +02:00
|
|
|
function fix_api($file, $dry_run=false)
|
2016-03-22 00:55:18 +01:00
|
|
|
{
|
2016-04-27 21:26:13 +02:00
|
|
|
global $prog, $replace, $add_use_api;
|
2016-03-22 00:55:18 +01:00
|
|
|
if (basename($file) == $prog) return true; // dont fix ourself ;-)
|
|
|
|
|
2016-04-07 22:42:06 +02:00
|
|
|
if (($content = $content_in = file_get_contents($file)) === false) return false;
|
2016-03-22 00:55:18 +01:00
|
|
|
|
2016-04-29 15:03:04 +02:00
|
|
|
if (!preg_match("|<\?php\n+\s*/\*\*?.*\*/|msU", $content))
|
2016-03-22 00:55:18 +01:00
|
|
|
{
|
|
|
|
error_log("No file-level phpDoc block found in $file to add 'use EGroupware\\Api;'\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-04-29 15:03:04 +02:00
|
|
|
$content2 = preg_replace(array_keys($replace), array_values($replace), $content);
|
2016-04-27 21:26:13 +02:00
|
|
|
|
|
|
|
if ($content2 == $content_in) return true; // nothing changed
|
|
|
|
|
|
|
|
$content = preg_replace(array_keys($add_use_api), array_values($add_use_api), $content2);
|
2016-03-22 00:55:18 +01:00
|
|
|
|
|
|
|
// shorten some classes, if used, with further use declarations
|
2016-04-26 20:27:51 +02:00
|
|
|
foreach(array('Api\\Etemplate', 'Api\\Vfs', 'Api\\Acl', 'Api\\Egw', 'Api\\Framework', 'Api\\Link') as $namespace)
|
2016-03-22 00:55:18 +01:00
|
|
|
{
|
|
|
|
if (strpos($content, $namespace) !== false && strpos($content, 'use EGroupware\\'.$namespace) === false)
|
|
|
|
{
|
|
|
|
$content = strtr($content, array(
|
|
|
|
$namespace => str_replace('Api\\', '', $namespace),
|
|
|
|
"use EGroupware\\Api;" => "use EGroupware\\Api;\nuse EGroupware\\$namespace;"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 22:42:06 +02:00
|
|
|
if ($dry_run)
|
|
|
|
{
|
|
|
|
echo $content;
|
|
|
|
}
|
2016-04-27 21:26:13 +02:00
|
|
|
else
|
2016-04-07 22:42:06 +02:00
|
|
|
{
|
2016-04-26 20:27:51 +02:00
|
|
|
file_put_contents($file.'.new', $content);
|
|
|
|
$ret = 0;
|
|
|
|
system('/usr/bin/php -l '.$file.'.new', $ret);
|
|
|
|
system('/usr/bin/diff -u '.$file.' '.$file.'.new');
|
|
|
|
if (!$ret)
|
|
|
|
{
|
|
|
|
unlink($file);
|
|
|
|
rename($file.'.new', $file);
|
|
|
|
}
|
|
|
|
return !$ret;
|
2016-04-07 22:42:06 +02:00
|
|
|
}
|
2016-03-22 00:55:18 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loop recursive through directory and call fix_api for each php file
|
|
|
|
*
|
|
|
|
* @param string $dir
|
2016-04-07 22:42:06 +02:00
|
|
|
* @param boolean $dry_run =false true: only echo fixed file, not fix it
|
2016-03-22 00:55:18 +01:00
|
|
|
* @return boolean false on error
|
|
|
|
*/
|
2016-04-07 22:42:06 +02:00
|
|
|
function fix_api_recursive($dir, $dry_run=false)
|
2016-03-22 00:55:18 +01:00
|
|
|
{
|
|
|
|
if (!is_dir($dir)) return false;
|
|
|
|
|
|
|
|
foreach(scandir($dir) as $file)
|
|
|
|
{
|
|
|
|
if ($file == '.' || $file == '..') continue;
|
|
|
|
|
|
|
|
if (is_dir($dir.'/'.$file))
|
|
|
|
{
|
2016-04-07 22:42:06 +02:00
|
|
|
fix_api_recursive($dir.'/'.$file, $dry_run);
|
2016-03-22 00:55:18 +01:00
|
|
|
}
|
|
|
|
elseif(substr($file,-4) == '.php')
|
|
|
|
{
|
|
|
|
echo "\r".str_repeat(' ',100)."\r".$dir.'/'.$file.': ';
|
2016-04-07 22:42:06 +02:00
|
|
|
fix_api($dir.'/'.$file, $dry_run);
|
2016-03-22 00:55:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "\r".str_repeat(' ',100)."\r";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Give usage
|
|
|
|
*
|
|
|
|
* @param string $error =null
|
|
|
|
*/
|
|
|
|
function usage($error=null)
|
|
|
|
{
|
|
|
|
global $prog;
|
2016-04-29 15:03:04 +02:00
|
|
|
echo "Usage: $prog [-h|--help] [-d|--dry-run] file(s) or dir(s)\n\n";
|
2016-03-22 00:55:18 +01:00
|
|
|
if ($error) echo $error."\n\n";
|
|
|
|
exit($error ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = $_SERVER['argv'];
|
|
|
|
$prog = basename(array_shift($args));
|
|
|
|
|
|
|
|
if (!$args) usage();
|
|
|
|
|
2016-04-07 22:42:06 +02:00
|
|
|
$dry_run = false;
|
2016-04-29 15:03:04 +02:00
|
|
|
while(($arg = array_shift($args)) && $arg[0] == '-')
|
2016-03-22 00:55:18 +01:00
|
|
|
{
|
|
|
|
switch($arg)
|
|
|
|
{
|
|
|
|
case '-h':
|
|
|
|
case '--help':
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
|
2016-04-07 22:42:06 +02:00
|
|
|
case '-d':
|
|
|
|
case '--dry-run':
|
|
|
|
$dry_run = true;
|
|
|
|
break;
|
|
|
|
|
2016-03-22 00:55:18 +01:00
|
|
|
default:
|
|
|
|
if ($args) // not last argument
|
|
|
|
{
|
|
|
|
usage("Unknown argument '$arg'!");
|
|
|
|
}
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 15:03:04 +02:00
|
|
|
do {
|
|
|
|
if (!file_exists($arg)) usage("Error: $arg not found!");
|
2016-03-22 00:55:18 +01:00
|
|
|
|
2016-04-29 15:03:04 +02:00
|
|
|
if (!is_dir($arg))
|
|
|
|
{
|
|
|
|
fix_api($arg, $dry_run);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fix_api_recursive($arg, $dry_run);
|
|
|
|
}
|
2016-03-22 00:55:18 +01:00
|
|
|
}
|
2016-04-29 15:03:04 +02:00
|
|
|
while(($arg = array_shift($args)));
|