Extension.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\models\mysqldb;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class Extension extends ActiveRecord
  16. {
  17. public static function tableName()
  18. {
  19. return '{{%extensions}}';
  20. }
  21. public function rules()
  22. {
  23. $rules = [
  24. ['namespace', 'required'],
  25. ['namespace', 'filter', 'filter' => 'trim'],
  26. ['namespace', 'string', 'length' => [1, 50]],
  27. ['namespace', 'validateNamespace'],
  28. ['package', 'required'],
  29. ['package', 'filter', 'filter' => 'trim'],
  30. ['package', 'string', 'length' => [1, 50]],
  31. ['folder', 'required'],
  32. ['folder', 'filter', 'filter' => 'trim'],
  33. ['folder', 'string', 'length' => [1, 50]],
  34. ['name', 'required'],
  35. ['name', 'filter', 'filter' => 'trim'],
  36. ['name', 'string', 'length' => [1, 50]],
  37. ['config_file_path', 'required'],
  38. ['config_file_path', 'filter', 'filter' => 'trim'],
  39. ['config_file_path', 'string', 'length' => [1, 255]],
  40. ['version', 'required'],
  41. ['version', 'filter', 'filter' => 'trim'],
  42. ['version', 'string', 'length' => [1, 50]],
  43. ];
  44. return $rules;
  45. }
  46. public function validateNamespace($attribute, $params)
  47. {
  48. if ($this->id) {
  49. $one = Extension::find()
  50. ->where(' id != :id AND namespace = :namespace ', [':id'=>$this->id, ':namespace'=>$this->namespace])
  51. ->one();
  52. if ($one['id']) {
  53. $this->addError($attribute, 'this namespace['.$this->namespace.'] is exist!');
  54. }
  55. } else {
  56. $one = Extension::find()
  57. ->where('namespace = :namespace', [':namespace' => $this->namespace])
  58. ->one();
  59. if ($one['id']) {
  60. $this->addError($attribute, 'this namespace['.$this->namespace.'] is exist!');
  61. }
  62. }
  63. }
  64. }