1 | <?php |
||
9 | class BRelatedActionDelete extends CAction |
||
10 | { |
||
11 | 2 | public function run() |
|
23 | |||
24 | 1 | private function tryDelete() |
|
56 | |||
57 | /* private function parseError($error, $pk) |
||
58 | { |
||
59 | if( !preg_match('/a foreign key constraint fails \((.+)\). The SQL/', $error, $matchesQuery) ) |
||
60 | return null; |
||
61 | |||
62 | if( !preg_match('/`(\w+)`.`(\w+)`.+FOREIGN KEY.+`(\w+)`.+REFERENCES+.`(\w+)`/', $matchesQuery[1], $matches) ) |
||
63 | return null; |
||
64 | |||
65 | $db = $matches[1]; |
||
66 | $table = $matches[2]; |
||
67 | $field = $matches[3]; |
||
68 | |||
69 | if( !$records = $this->getRelatedRecords($table, $field, $pk) ) |
||
70 | return null; |
||
71 | |||
72 | return $this->createResponse($table, $records); |
||
73 | } |
||
74 | |||
75 | private function getRelatedRecords($table, $field, $pk) |
||
76 | { |
||
77 | $criteria = new CDbCriteria(); |
||
78 | $criteria->compare($field, $pk); |
||
79 | |||
80 | $command = Yii::app()->db->getSchema()->commandBuilder->createFindCommand($table, $criteria); |
||
81 | return $command->queryAll(); |
||
82 | } |
||
83 | |||
84 | private function createResponse($table, $records) |
||
85 | { |
||
86 | switch($table) |
||
87 | { |
||
88 | case $this->getFullTableName(BProductParam::model()->tableName()): |
||
89 | $urls = array(); |
||
90 | foreach(CHtml::listData($records, 'product_id', 'product_id') as $productId) |
||
91 | { |
||
92 | $urls[$productId] = CHtml::link('Товар id='.$productId, '/backend/product/product/update/'.$productId, array('target' => '_blank')); |
||
93 | } |
||
94 | $out = 'Товары имеющие сввязанные параметры:<br/>'; |
||
95 | $out .= implode('<br/>', $urls); |
||
96 | break; |
||
97 | } |
||
98 | |||
99 | return $out; |
||
100 | } |
||
101 | |||
102 | private function getFullTableName($shortName) |
||
103 | { |
||
104 | $normalShortName = trim($shortName, '{}'); |
||
105 | return Yii::app()->db->tablePrefix.$normalShortName; |
||
106 | }*/ |
||
107 | } |