Skip to content

Commit

Permalink
Moved Transfer action to Transfer controller
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 28, 2016
1 parent 623a59e commit ecc900a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
41 changes: 0 additions & 41 deletions src/controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,47 +525,6 @@ public function actionRenew()
return $this->redirect(Yii::$app->request->referrer);
}

public function actionTransfer()
{
$model = new Domain();
$model->scenario = 'transfer';
$transferDataProvider = null;
if (Yii::$app->request->isPost) {
$post = Yii::$app->request->post($model->formName(), []);
if (!empty($post[0]['domains'])) {
$domains = [];
foreach (StringHelper::explode($post[0]['domains'], "\n") as $line) {
preg_match('/^([a-z0-9][0-9a-z.-]+)(?:[,;\s]+)(.*)/i', $line, $matches);
if ($matches) {
$domain = strtolower($matches[1]);
$password = $matches[2];
$domains[] = compact('domain', 'password');
}
}
$post = $domains;
}

$collection = (new Collection(['model' => $model]))->load($post);
$models = $collection->getModels();

foreach ($models as $model) {
try {
Domain::perform('CheckTransfer', $model->getAttributes(['domain', 'password']));
} catch (ErrorResponseException $e) {
$model->addError('password', $e->getMessage());
}
}

Yii::$app->session->setFlash('transferGrid', 1);
$transferDataProvider = new ArrayDataProvider(['models' => $models]);
}

return $this->render('transfer', [
'model' => $model,
'transferDataProvider' => $transferDataProvider,
]);
}

public function actionGetPassword()
{
$return = ['status' => 'error'];
Expand Down
41 changes: 41 additions & 0 deletions src/controllers/TransferController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,45 @@ public function actionIndex()
'transferDataProvider' => $transferDataProvider,
]);
}

public function actionTransfer()
{
$model = new Domain();
$model->scenario = 'transfer';
$transferDataProvider = null;
if (Yii::$app->request->isPost) {
$post = Yii::$app->request->post($model->formName(), []);
if (!empty($post[0]['domains'])) {
$domains = [];
foreach (StringHelper::explode($post[0]['domains'], "\n") as $line) {
preg_match('/^([a-z0-9][0-9a-z.-]+)(?:[,;\s]+)(.*)/i', $line, $matches);
if ($matches) {
$domain = strtolower($matches[1]);
$password = $matches[2];
$domains[] = compact('domain', 'password');
}
}
$post = $domains;
}

$collection = (new Collection(['model' => $model]))->load($post);
$models = $collection->getModels();

foreach ($models as $model) {
try {
Domain::perform('CheckTransfer', $model->getAttributes(['domain', 'password']));
} catch (ErrorResponseException $e) {
$model->addError('password', $e->getMessage());
}
}

Yii::$app->session->setFlash('transferGrid', 1);
$transferDataProvider = new ArrayDataProvider(['models' => $models]);
}

return $this->render('index', [
'model' => $model,
'transferDataProvider' => $transferDataProvider,
]);
}
}

0 comments on commit ecc900a

Please sign in to comment.