SystemCrudServices.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace app\services\system;
  14. use app\dao\system\SystemCrudDao;
  15. use app\services\BaseServices;
  16. use crmeb\exceptions\AdminException;
  17. use crmeb\services\crud\Controller;
  18. use crmeb\services\crud\Dao;
  19. use crmeb\services\crud\Make;
  20. use crmeb\services\crud\Model;
  21. use crmeb\services\crud\Route;
  22. use crmeb\services\crud\Service;
  23. use crmeb\services\crud\Validate;
  24. use crmeb\services\crud\ViewApi;
  25. use crmeb\services\crud\ViewPages;
  26. use crmeb\services\crud\ViewRouter;
  27. use crmeb\services\FileService;
  28. use Phinx\Db\Adapter\AdapterFactory;
  29. use think\facade\Db;
  30. use think\helper\Str;
  31. use think\migration\db\Table;
  32. /**
  33. * Class SystemCrudServices
  34. * @author 等风来
  35. * @email 136327134@qq.com
  36. * @date 2023/4/6
  37. * @package app\services\system
  38. */
  39. class SystemCrudServices extends BaseServices
  40. {
  41. //不能生成的系统自带表
  42. const NOT_CRUD_TABANAME = [
  43. 'system_config', 'system_attachment', 'system_attachment_category', 'system_config_tab',
  44. 'system_admin', 'eb_system_city', 'system_log', 'system_menus', 'system_notice',
  45. 'system_notice_admin', 'system_notification', 'system_role', 'system_route',
  46. 'system_route_cate', 'system_storage', 'system_timer', 'system_user_level',
  47. 'system_crud', 'wechat_key', 'user_label_relation', 'user_brokerage_frozen',
  48. 'user_brokerage', 'store_product_cate', 'store_bargain_user_help', 'shipping_templates_region',
  49. 'shipping_templates_no_delivery', 'shipping_templates_free', 'other_order_status', 'lang_code',
  50. 'lang_country', 'app_version', 'user', 'wechat_user', 'template_message', 'store_order', 'other_order',
  51. 'store_order_cart_info', 'store_order_economize', 'store_order_invoice', 'store_order_refund',
  52. 'store_order_status', 'store_pink'
  53. ];
  54. /**
  55. * SystemCrudServices constructor.
  56. * @param SystemCrudDao $dao
  57. */
  58. public function __construct(SystemCrudDao $dao)
  59. {
  60. $this->dao = $dao;
  61. }
  62. /**
  63. * @return array
  64. * @author 等风来
  65. * @email 136327134@qq.com
  66. * @date 2023/4/11
  67. */
  68. public function getList()
  69. {
  70. [$page, $limit] = $this->getPageValue();
  71. $list = $this->dao->selectList([], 'add_time,id,name,table_name,table_comment,table_collation', $page, $limit, 'id desc');
  72. $count = $this->dao->count();
  73. return compact('list', 'count');
  74. }
  75. /**
  76. * 数据库字段类型
  77. * @return \string[][]
  78. * @author 等风来
  79. * @email 136327134@qq.com
  80. * @date 2023/4/11
  81. */
  82. public function getTabelRule()
  83. {
  84. $rule = [
  85. 'varchar' => 'string',
  86. 'int' => 'integer',
  87. 'biginteger' => 'bigint',
  88. 'tinyint' => 'boolean',
  89. ];
  90. return [
  91. 'types' => [
  92. 'varchar',
  93. 'char',
  94. 'text',
  95. 'longtext',
  96. 'tinytext',
  97. 'enum',
  98. 'blob',
  99. 'binary',
  100. 'varbinary',
  101. 'datetime',
  102. 'timestamp',
  103. 'time',
  104. 'date',
  105. 'year',
  106. 'boolean',
  107. 'tinyint',
  108. 'int',
  109. 'decimal',
  110. 'float',
  111. 'json',
  112. 'addTimestamps',
  113. 'addSoftDelete',
  114. ],
  115. 'rule' => $rule
  116. ];
  117. }
  118. /**
  119. * 改变数据库类型
  120. * @param string $type
  121. * @return string
  122. * @author 等风来
  123. * @email 136327134@qq.com
  124. * @date 2023/4/13
  125. */
  126. public function changeTabelRule(string $type)
  127. {
  128. if (!in_array($type, $this->getTabelRule()['types'])) {
  129. throw new AdminException(500047);
  130. }
  131. return $this->getTabelRule()['rule'][$type] ?? $type;
  132. }
  133. /**
  134. * @param string $tableName
  135. * @return mixed
  136. * @author 等风来
  137. * @email 136327134@qq.com
  138. * @date 2023/4/14
  139. */
  140. public function getTableInfo(string $tableName)
  141. {
  142. $sql = 'SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?';
  143. $tableInfo = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
  144. return $tableInfo[0] ?? [];
  145. }
  146. /**
  147. * 获取表字段
  148. * @param string $tableName
  149. * @return mixed
  150. * @author 等风来
  151. * @email 136327134@qq.com
  152. * @date 2023/4/7
  153. */
  154. public function getColumnNamesList(string $tableName)
  155. {
  156. $sql = 'SELECT * FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND table_name = ? ORDER BY ORDINAL_POSITION';
  157. $column = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
  158. $columns = [];
  159. foreach ($column as $item) {
  160. $column = [
  161. 'name' => $item['COLUMN_NAME'],
  162. 'type' => $item['DATA_TYPE'],
  163. 'dataType' => stripos($item['COLUMN_TYPE'], '(') !== false ? substr_replace($item['COLUMN_TYPE'], '', stripos($item['COLUMN_TYPE'], ')') + 1) : $item['COLUMN_TYPE'],
  164. 'default' => $item['COLUMN_DEFAULT'],
  165. 'null' => $item['IS_NULLABLE'] == 'YES',
  166. 'primaryKey' => $item['COLUMN_KEY'] == 'PRI',
  167. 'unsigned' => (bool)stripos($item['COLUMN_TYPE'], 'unsigned'),
  168. 'autoIncrement' => stripos($item['EXTRA'], 'auto_increment') !== false,
  169. 'comment' => $item['COLUMN_COMMENT'],
  170. 'limit' => $item['CHARACTER_MAXIMUM_LENGTH'] ?: $item['NUMERIC_PRECISION'],
  171. ];
  172. $columns[$item['COLUMN_NAME']] = $column;
  173. }
  174. return $columns;
  175. }
  176. /**
  177. * @param array $data
  178. * @return array
  179. * @author 等风来
  180. * @email 136327134@qq.com
  181. * @date 2023/4/12
  182. */
  183. public function valueReplace(array $data)
  184. {
  185. $replace = ['phar://'];
  186. $newData = [];
  187. foreach ($data as $key => $item) {
  188. if (is_array($item)) {
  189. $item = $this->valueReplace($item);
  190. } else {
  191. $item = str_replace($replace, '', $item);
  192. }
  193. $newData[str_replace($replace, '', $key)] = $item;
  194. }
  195. return $newData;
  196. }
  197. /**
  198. * 创建
  199. * @param array $data
  200. * @return mixed
  201. * @author 等风来
  202. * @email 136327134@qq.com
  203. * @date 2023/4/11
  204. */
  205. public function createCrud(array $data)
  206. {
  207. $tableName = $data['tableName'];
  208. $tableComment = $data['tableComment'] ?? $data['menuName'];
  209. $tableField = $this->valueReplace($data['tableField']);
  210. $filePath = $this->valueReplace($data['filePath']);
  211. if ($this->dao->value(['table_name' => $tableName])) {
  212. throw new AdminException(500048);
  213. }
  214. $data['softDelete'] = false;
  215. //创建数据库
  216. if ($tableField && !$data['isTable']) {
  217. $tableCreateInfo = $this->makeDatebase($tableName, $tableComment, $tableField);
  218. if ($tableCreateInfo['softDelete']) {
  219. $data['softDelete'] = true;
  220. }
  221. }
  222. if (in_array($tableName, self::NOT_CRUD_TABANAME)) {
  223. throw new AdminException(500044);
  224. }
  225. //读取表结构
  226. $column = $this->getColumnNamesList($tableName);
  227. if (!$column) {
  228. throw new AdminException(500049, ['_name' => $tableName]);
  229. }
  230. $tableInfo = $this->getTableInfo($tableName);
  231. //获取主键
  232. foreach ($column as $value) {
  233. if ($value['primaryKey']) {
  234. $data['key'] = $value['name'];
  235. break;
  236. }
  237. }
  238. $routeName = 'crud/' . Str::snake($tableName);
  239. $uniqueAuth = Str::snake($tableName) . '-crud-list-index';
  240. //增加保存的绝对路径
  241. foreach ($filePath as $k => $i) {
  242. if (in_array($k, ['pages', 'router', 'api'])) {
  243. $filePath[$k] = Make::adminTemplatePath() . $i;
  244. } else {
  245. $filePath[$k] = app()->getRootPath() . $i;
  246. }
  247. }
  248. //创建菜单
  249. if (!$data['menuName']) {
  250. $data['menuName'] = $tableName;
  251. }
  252. $dataMenu = [
  253. 'pid' => $data['pid'],
  254. 'menu_name' => $data['menuName'],
  255. 'menu_path' => '/' . $routeName,
  256. 'auth_type' => 1,
  257. 'is_show' => 1,
  258. 'is_del' => 0,
  259. 'unique_auth' => $uniqueAuth,
  260. 'is_header' => $data['pid'] ? 0 : 1,
  261. ];
  262. $res = $this->transaction(function () use ($tableInfo, $filePath, $tableName, $routeName, $data, $dataMenu) {
  263. $menuInfo = app()->make(SystemMenusServices::class)->save($dataMenu);
  264. //写入路由权限
  265. $cateId = app()->make(SystemRouteServices::class)->topCateId('adminapi');
  266. $ruleData = [
  267. [
  268. 'path' => $routeName,
  269. 'method' => 'GET',
  270. 'name' => $data['menuName'] . '列表接口',
  271. 'app_name' => 'adminapi',
  272. 'cate_id' => $cateId,
  273. 'unique_auth' => '',
  274. 'add_time' => date('Y-m-d H:i:s')
  275. ],
  276. [
  277. 'path' => $routeName . '/create',
  278. 'method' => 'GET',
  279. 'name' => $data['menuName'] . '获取创建表单接口',
  280. 'app_name' => 'adminapi',
  281. 'cate_id' => $cateId,
  282. 'unique_auth' => Str::snake($tableName) . '-add',
  283. 'add_time' => date('Y-m-d H:i:s')
  284. ],
  285. [
  286. 'path' => $routeName,
  287. 'method' => 'POST',
  288. 'name' => $data['menuName'] . '保存数据接口',
  289. 'app_name' => 'adminapi',
  290. 'cate_id' => $cateId,
  291. 'unique_auth' => '',
  292. 'add_time' => date('Y-m-d H:i:s')
  293. ],
  294. [
  295. 'path' => $routeName . '/<id>/edit',
  296. 'method' => 'GET',
  297. 'name' => $data['menuName'] . '获取修改表单接口',
  298. 'app_name' => 'adminapi',
  299. 'cate_id' => $cateId,
  300. 'unique_auth' => '',
  301. 'add_time' => date('Y-m-d H:i:s')
  302. ],
  303. [
  304. 'path' => $routeName . '/<id>',
  305. 'method' => 'PUT',
  306. 'name' => $data['menuName'] . '修改数据接口',
  307. 'app_name' => 'adminapi',
  308. 'cate_id' => $cateId,
  309. 'unique_auth' => '',
  310. 'add_time' => date('Y-m-d H:i:s')
  311. ],
  312. [
  313. 'path' => $routeName . '/<id>',
  314. 'method' => 'DELETE',
  315. 'name' => $data['menuName'] . '删除数据接口',
  316. 'app_name' => 'adminapi',
  317. 'cate_id' => $cateId,
  318. 'unique_auth' => '',
  319. 'add_time' => date('Y-m-d H:i:s')
  320. ],
  321. ];
  322. app()->make(SystemRouteServices::class)->saveAll($ruleData);
  323. //记录权限加入菜单表
  324. $menuData = [];
  325. foreach ($ruleData as $item) {
  326. $menuData[] = [
  327. 'pid' => $menuInfo->id,
  328. 'methods' => $item['method'],
  329. 'api_url' => $item['path'],
  330. 'unique_auth' => $item['unique_auth'],
  331. 'menu_name' => $item['name'],
  332. 'is_del' => 0,
  333. 'auth_type' => 2,
  334. ];
  335. }
  336. $menus = app()->make(SystemMenusServices::class)->saveAll($menuData);
  337. $menuIds = array_column($menus->toArray(), 'id');
  338. array_push($menuIds, $menuInfo->id);
  339. //生成文件
  340. $make = $this->makeFile($tableName, $routeName, config('app.crud_make', false), $data, $filePath);
  341. $makePath = [];
  342. foreach ($make as $key => $item) {
  343. $makePath[$key] = $item['path'];
  344. }
  345. //记录crud生成
  346. $res = $this->dao->save([
  347. 'pid' => $data['pid'],
  348. 'name' => $data['menuName'],
  349. 'model_name' => $data['modelName'],
  350. 'table_name' => $tableName,
  351. 'table_comment' => $tableInfo['TABLE_COMMENT'] ?? '',
  352. 'table_collation' => $tableInfo['TABLE_COLLATION'] ?? '',
  353. 'field' => json_encode($data),//提交的数据
  354. 'menu_ids' => json_encode($menuIds),//生成的菜单id
  355. 'make_path' => json_encode($makePath),
  356. 'add_time' => time()
  357. ]);
  358. return $res;
  359. });
  360. return $res->toArray();
  361. }
  362. /**
  363. * 获取数据库配置
  364. * @return array
  365. */
  366. protected function getDbConfig(): array
  367. {
  368. $default = app()->config->get('database.default');
  369. $config = app()->config->get("database.connections.{$default}");
  370. if (0 == $config['deploy']) {
  371. $dbConfig = [
  372. 'adapter' => $config['type'],
  373. 'host' => $config['hostname'],
  374. 'name' => $config['database'],
  375. 'user' => $config['username'],
  376. 'pass' => $config['password'],
  377. 'port' => $config['hostport'],
  378. 'charset' => $config['charset'],
  379. 'table_prefix' => $config['prefix'],
  380. ];
  381. } else {
  382. $dbConfig = [
  383. 'adapter' => explode(',', $config['type'])[0],
  384. 'host' => explode(',', $config['hostname'])[0],
  385. 'name' => explode(',', $config['database'])[0],
  386. 'user' => explode(',', $config['username'])[0],
  387. 'pass' => explode(',', $config['password'])[0],
  388. 'port' => explode(',', $config['hostport'])[0],
  389. 'charset' => explode(',', $config['charset'])[0],
  390. 'table_prefix' => explode(',', $config['prefix'])[0],
  391. ];
  392. }
  393. $table = app()->config->get('database.migration_table', 'migrations');
  394. $dbConfig['default_migration_table'] = $dbConfig['table_prefix'] . $table;
  395. return $dbConfig;
  396. }
  397. public function getAdapter()
  398. {
  399. $options = $this->getDbConfig();
  400. $adapter = AdapterFactory::instance()->getAdapter($options['adapter'], $options);
  401. if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) {
  402. $adapter = AdapterFactory::instance()->getWrapper('prefix', $adapter);
  403. }
  404. return $adapter;
  405. }
  406. /**
  407. * 创建数据库
  408. * @param string $tableName
  409. * @param string $tableComment
  410. * @param array $tableField
  411. * @return array
  412. * @author 等风来
  413. * @email 136327134@qq.com
  414. * @date 2023/4/7
  415. */
  416. public function makeDatebase(string $tableName, string $tableComment, array $tableField = [])
  417. {
  418. $softDelete = false;
  419. $timestamps = false;
  420. $indexField = [];
  421. //创建表
  422. $table = new Table($tableName, ['comment' => $tableComment], $this->getAdapter());
  423. //创建字段
  424. foreach ($tableField as $item) {
  425. $option = [];
  426. if (isset($item['limit'])) {
  427. $option['limit'] = (int)$item['limit'];
  428. }
  429. if (isset($item['default'])) {
  430. $option['default'] = $item['default'];
  431. }
  432. //创建伪删除
  433. if ($item['field_type'] === 'addSoftDelete') {
  434. $table->addSoftDelete();
  435. $softDelete = true;
  436. } else if ($item['field_type'] === 'addTimestamps') {
  437. //创建修改和增加时间
  438. $table->addTimestamps();
  439. $timestamps = true;
  440. } else {
  441. $option['comment'] = $item['comment'];
  442. $table->addColumn($item['field'], $this->changeTabelRule($item['field_type']), $option);
  443. }
  444. }
  445. //创建索引
  446. if (!empty($data['tableIndex'])) {
  447. $indexField = $data['tableIndex'];
  448. foreach ($data['tableIndex'] as $item) {
  449. $table->addIndex($item);
  450. }
  451. }
  452. //执行创建
  453. $table->create();
  454. return compact('indexField', 'softDelete', 'timestamps');
  455. }
  456. /**
  457. * 创建文件返回文件路径和内容
  458. * @param string $tableName
  459. * @param string $routeName
  460. * @param bool $isMake
  461. * @param array $options
  462. * @param array $filePath
  463. * @param string $basePath
  464. * @return array[]
  465. * @author 等风来
  466. * @email 136327134@qq.com
  467. * @date 2023/4/7
  468. */
  469. public function makeFile(string $tableName, string $routeName, bool $isMake = false, array $options = [], array $filePath = [], string $basePath = '')
  470. {
  471. $options['fromField'] = is_array($options['fromField']) ? $options['fromField'] : [];
  472. $options['columnField'] = is_array($options['columnField']) ? $options['columnField'] : [];
  473. //生成模型
  474. $model = app()->make(Model::class);
  475. $model->setFilePathName($filePath['model'] ?? '')->setbasePath($basePath)->handle($tableName, $options);
  476. //生成dao
  477. $dao = app()->make(Dao::class);
  478. $dao->setFilePathName($filePath['dao'] ?? '')->setbasePath($basePath)->handle($tableName, [
  479. 'usePath' => $model->getUsePath(),
  480. ]);
  481. //生成service
  482. $service = app()->make(Service::class);
  483. $service->setFilePathName($filePath['service'] ?? '')->setbasePath($basePath)->handle($tableName, [
  484. 'field' => $options['fromField'],
  485. 'key' => $options['key'],
  486. 'usePath' => $dao->getUsePath(),
  487. 'modelName' => $options['modelName'] ?? '',
  488. ]);
  489. //生成验证器
  490. $validate = app()->make(Validate::class);
  491. $validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName);
  492. //生成控制器
  493. $controller = app()->make(Controller::class);
  494. $controller->setFilePathName($filePath['controller'] ?? '')->setbasePath($basePath)->handle($tableName, [
  495. 'usePath' => $service->getUsePath(),
  496. 'validateName' => '\\' . str_replace('/', '\\', $validate->getUsePath()) . '::class',
  497. 'field' => array_column($options['fromField'], 'field'),
  498. ]);
  499. //生成路由
  500. $route = app()->make(Route::class);
  501. $route->setFilePathName($filePath['route'] ?? '')->setbasePath($basePath)->handle($tableName, [
  502. 'menus' => $options['menuName'],
  503. 'route' => $routeName
  504. ]);
  505. //生成前台路由
  506. $viewRouter = app()->make(ViewRouter::class);
  507. $viewRouter->setFilePathName($filePath['router'] ?? '')->setbasePath($basePath)->handle($tableName, [
  508. 'route' => $routeName,
  509. 'menuName' => $options['menuName'],
  510. ]);
  511. //生成前台接口
  512. $viewApi = app()->make(ViewApi::class);
  513. $viewApi->setFilePathName($filePath['api'] ?? '')->setbasePath($basePath)->handle($tableName, [
  514. 'route' => $routeName,
  515. ]);
  516. //生成前台页面
  517. $viewPages = app()->make(ViewPages::class);
  518. $viewPages->setFilePathName($filePath['pages'] ?? '')->setbasePath($basePath)->handle($tableName, [
  519. 'field' => $options['columnField'],
  520. 'route' => $routeName,
  521. 'key' => $options['key'],
  522. 'pathApiJs' => '@/' . str_replace('\\', '/', str_replace([Make::adminTemplatePath(), '.js'], '', $viewApi->getPath())),
  523. ]);
  524. //创建文件
  525. if ($isMake) {
  526. FileService::batchMakeFiles([$model, $validate, $dao, $service, $controller, $route, $viewApi, $viewPages, $viewRouter]);
  527. }
  528. return [
  529. 'controller' => [
  530. 'path' => $this->replace($controller->getPath()),
  531. 'content' => $controller->getContent()
  532. ],
  533. 'model' => [
  534. 'path' => $this->replace($model->getPath()),
  535. 'content' => $model->getContent()
  536. ],
  537. 'dao' => [
  538. 'path' => $this->replace($dao->getPath()),
  539. 'content' => $dao->getContent()
  540. ],
  541. 'route' => [
  542. 'path' => $this->replace($route->getPath()),
  543. 'content' => $route->getContent()
  544. ],
  545. 'service' => [
  546. 'path' => $this->replace($service->getPath()),
  547. 'content' => $service->getContent()
  548. ],
  549. 'validate' => [
  550. 'path' => $this->replace($validate->getPath()),
  551. 'content' => $validate->getContent()
  552. ],
  553. 'router' => [
  554. 'path' => $this->replace($viewRouter->getPath()),
  555. 'content' => $viewRouter->getContent()
  556. ],
  557. 'api' => [
  558. 'path' => $this->replace($viewApi->getPath()),
  559. 'content' => $viewApi->getContent()
  560. ],
  561. 'pages' => [
  562. 'path' => $this->replace($viewPages->getPath()),
  563. 'content' => $viewPages->getContent()
  564. ],
  565. ];
  566. }
  567. protected function replace(string $path)
  568. {
  569. return str_replace([app()->getRootPath(), Make::adminTemplatePath()], '', $path);
  570. }
  571. /**
  572. * @param string $tableName
  573. * @param bool $fullName
  574. * @return string
  575. * @author 等风来
  576. * @email 136327134@qq.com
  577. * @date 2023/4/7
  578. */
  579. public function getTableName(string $tableName, bool $fullName = true)
  580. {
  581. $tablePrefix = config('database.connections.mysql.prefix');
  582. $pattern = '/^' . $tablePrefix . '/i';
  583. return ($fullName ? $tablePrefix : '') . (preg_replace($pattern, '', $tableName));
  584. }
  585. }