Sql.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\Core\FileReader\Reader;
  3. use ModulesGarden\Servers\ZimbraEmail\Core\ServiceLocator;
  4. use ModulesGarden\Servers\ZimbraEmail\Core\ModuleConstants;
  5. /**
  6. * Description of Sql
  7. *
  8. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  9. */
  10. class Sql extends AbstractType
  11. {
  12. protected function loadFile()
  13. {
  14. $return = '';
  15. try
  16. {
  17. if (file_exists($this->path . DS . $this->file))
  18. {
  19. $collation = $this->getWHMCSTablesCollation();
  20. $charset = $this->getWHMCSTablesCharset();
  21. $return = file_get_contents($this->path . DS . $this->file);
  22. $return = str_replace("#collation#", $collation, $return);
  23. $return = str_replace("#charset#", $charset, $return);
  24. $return = str_replace("#prefix#", ModuleConstants::getPrefixDataBase(), $return);
  25. foreach ($this->renderData as $key => $value)
  26. {
  27. $return = str_replace("#$key#", $value, $return);
  28. }
  29. }
  30. }
  31. catch (\Exception $e)
  32. {
  33. ServiceLocator::call('errorManager')->addError(self::class, $e->getMessage(), $e->getTrace());
  34. }
  35. $this->data = $return;
  36. }
  37. protected function getWHMCSTablesCollation()
  38. {
  39. $pdo = \Illuminate\Database\Capsule\Manager::connection()->getPdo();
  40. $query = $pdo->prepare("SHOW TABLE STATUS WHERE name = 'tblclients'");
  41. $query->execute();
  42. $result = $query->fetchObject();
  43. return $result->Collation;
  44. }
  45. protected function getWHMCSTablesCharset()
  46. {
  47. require ROOTDIR . DS . 'configuration.php';
  48. $pdo = \Illuminate\Database\Capsule\Manager::connection()->getPdo();
  49. $query = $pdo->prepare("SELECT CCSA.character_set_name as Charset FROM information_schema.`TABLES` T,
  50. information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
  51. WHERE CCSA.collation_name = T.table_collation
  52. AND T.table_schema = :db_name
  53. AND T.table_name = 'tblclients';");
  54. $query->execute(['db_name' => $db_name]);
  55. $result = $query->fetchObject();
  56. return $result->Charset;
  57. }
  58. }