Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
refactoring done #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Yadav committed Oct 8, 2017
1 parent 472ac8b commit d929873
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 249 deletions.
111 changes: 97 additions & 14 deletions protected/commands/VillageUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,105 @@
*/
class VillageUpdateCommand extends CConsoleCommand
{

/**
* #201710051351:Kovai:thevikas
* #201710081840:Kovai:thevikas
*/
public function actionTamilnadu()
public function actionIndex($id_state)
{
require_once __DIR__ . '/states/TamilnaduVillages.php';
TamilnaduVillages();
$state = State::model ()->findByPk ( $id_state );

$vills = Village::model ()->findAll (
[
'select' => 'distinct dist_name',
'condition' => 'id_district is null and state_name=?',
'params' => [
$state->name
]
] );

echo "Total " . count ( $vills ) . " found.\n";
if (count ( $vills ) == 0)
return;

foreach ( $vills as $dist )
{
$dist_name = $dist->dist_name;

if (preg_match ( '/ContentPlaceHolder/', $dist_name ))
{
Village::model ()->deleteAllByAttributes (
[
'dist_name' => $dist_name
] );
continue;
}

if (empty ( trim ( $dist_name ) ) || strlen ( $dist_name ) == 1)
continue;

echo "$dist_name...";
/*
* else if ('TIRUVARUR' == $dist_name)
* $dist_name = 'Thiruvarur';
* else if ('VILLUPURAM' == $dist_name)
* $dist_name = 'Viluppuram';
*/

$place = Place::model ()->findByAttributes (
[
'id_state' => $id_state,
'dt_name' => $dist_name,
'sdt_code' => 0,
'tv_code' => 0
] );
if (! $place)
{
while ( true )
{
echo 'Could not find district [' . $dist_name . "]\n";
echo 'Please provide the place id (0 for new):';
$id_place2 = intval ( fgets ( STDIN ) );
if ($id_place2)
$place = Place::model ()->findByPk ( $id_place2 );
else
{
$place = new Place();
$place->id_state = $id_state;
$place->name = $place->dt_name = $dist_name;
$place->state_code = $place->sdt_code = $place->tv_code = 0;
if(!$place->save())
{
print_r($place->errors);
die;
}
}
if (! $place)
{
echo "$id_place2 Not found.\n";
$id_place2 = 0;
}
else
{
echo "{$place->id_place2} found as [{$place->dt_name}] vs [$dist_name] Confirm (y/n)?";
$yn = strtolower ( trim ( fgets ( STDIN ) ) );
if ('y' == $yn)
break;
}
}
}
$rups = Village::model ()->updateAll (
[
'id_district' => $place->id_place2,
'id_state' => $id_state,
'state_name' => null,
'dist_name' => null,
'del1' => null,
'del2' => null
], 'dist_name = ?', [
$dist->dist_name
] );
echo "$rups updated\n";
}
}

/**
* #201710051351:Kovai:thevikas
*/
public function actionKerala()
{
require_once __DIR__ . '/states/KeralaVillages.php';
KeralaVillages();
}

}
56 changes: 0 additions & 56 deletions protected/commands/states/KeralaVillages.php

This file was deleted.

177 changes: 0 additions & 177 deletions protected/commands/states/TamilnaduVillages.php

This file was deleted.

2 changes: 1 addition & 1 deletion protected/models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function rules()
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('state_code, dt_code, dt_name, sdt_code, tv_code, name, updated', 'required'),
array('dt_name, name', 'required'),
array('state_code, id_state, dt_code, sdt_code, tv_code, population, areasqkm, eci_ref, amly_count', 'numerical', 'integerOnly'=>true),
array('dt_name, sdt_name, name, slug', 'length', 'max'=>255),
array('st_code_2c, dt_code_2c', 'length', 'max'=>3),
Expand Down
2 changes: 1 addition & 1 deletion protected/models/Village.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function behaviors()
'CTimestampBehavior' => array (
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'created',
'updateAttribute' => null,
'updateAttribute' => 'updated',
)
];
}
Expand Down

0 comments on commit d929873

Please sign in to comment.