mirror of
https://github.com/Oreolek/kangana.git
synced 2024-05-18 17:08:19 +03:00
Smartresponder migration with all the fields
This commit is contained in:
parent
c5f5d0de3d
commit
34237c1d2f
|
@ -34,7 +34,6 @@ class Model_Client extends ORM {
|
||||||
),
|
),
|
||||||
'name' => array(
|
'name' => array(
|
||||||
array('not_empty'),
|
array('not_empty'),
|
||||||
array('min_length', array(':value', 5)),
|
|
||||||
),
|
),
|
||||||
'sex' => array(
|
'sex' => array(
|
||||||
array('max_length', array(':value', 1)),
|
array('max_length', array(':value', 1)),
|
||||||
|
|
|
@ -14,14 +14,14 @@ class Task_Migrate_Smartresponder extends Minion_Task
|
||||||
{
|
{
|
||||||
protected $_options = array(
|
protected $_options = array(
|
||||||
'csv' => NULL,
|
'csv' => NULL,
|
||||||
'group' => NULL,
|
'group_id' => NULL,
|
||||||
);
|
);
|
||||||
|
|
||||||
public function build_validation(Validation $validation)
|
public function build_validation(Validation $validation)
|
||||||
{
|
{
|
||||||
return parent::build_validation($validation)
|
return parent::build_validation($validation)
|
||||||
->rule('csv', 'not_empty') // Require this param
|
->rule('csv', 'not_empty') // Require this param
|
||||||
->rule('group', 'not_empty'); // Require this param
|
->rule('group_id', 'not_empty'); // Require this param
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +44,9 @@ class Task_Migrate_Smartresponder extends Minion_Task
|
||||||
$db->begin();
|
$db->begin();
|
||||||
$transcoder = Transcoder::create();
|
$transcoder = Transcoder::create();
|
||||||
|
|
||||||
$group = ORM::factory('Group')->where('name', '=', $params['group'])->find();
|
$group = ORM::factory('Group')->where('id', '=', $params['group_id'])->find();
|
||||||
if ( ! $group->loaded()) {
|
if ( ! $group->loaded()) {
|
||||||
echo "No group with name " . $params['group'] . " found.\n";
|
echo "No group with id " . $params['group_id'] . " found.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,24 +54,37 @@ class Task_Migrate_Smartresponder extends Minion_Task
|
||||||
{
|
{
|
||||||
if (($handle = fopen($path, "r")) !== FALSE) {
|
if (($handle = fopen($path, "r")) !== FALSE) {
|
||||||
echo "File opened.\n";
|
echo "File opened.\n";
|
||||||
$query = DB::query(
|
|
||||||
Database::INSERT,
|
|
||||||
'INSERT INTO clients (email, name, group_id)
|
|
||||||
VALUES (:email, :name, :group_id)'
|
|
||||||
)
|
|
||||||
->bind(':email', $email)
|
|
||||||
->bind(':name', $name)
|
|
||||||
->bind(':group_id', $group->id);
|
|
||||||
|
|
||||||
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
||||||
$email = $data[0];
|
$client = ORM::factory('Client')->where('email', '=', $data[0]);
|
||||||
$name = $transcoder->transcode($data[1] . ' ' . $data[2], 'cp1251');
|
if (!$client->loaded()) {
|
||||||
$sex = $data[5];
|
$client = ORM::factory('Client');
|
||||||
$referrer = $data[13];
|
$client->email = $data[0];
|
||||||
$city = $transcoder->transcode($data[7], 'cp1251');
|
}
|
||||||
$country = $data[6];
|
$name = trim($transcoder->transcode($data[1] . ' ' . $data[2], 'cp1251'));
|
||||||
|
$client->name = $name;
|
||||||
|
$client->sex = $data[5];
|
||||||
|
if (!empty($data[13]))
|
||||||
|
{
|
||||||
|
$client->referrer = $data[13];
|
||||||
|
}
|
||||||
|
if (!empty($data[7]))
|
||||||
|
{
|
||||||
|
$client->city = $transcoder->transcode($data[7], 'cp1251');
|
||||||
|
}
|
||||||
|
if (!empty($data[6]))
|
||||||
|
{
|
||||||
|
$client->country = $data[6];
|
||||||
|
}
|
||||||
echo "Importing client " . $name . ".\n";
|
echo "Importing client " . $name . ".\n";
|
||||||
$query->execute();
|
try
|
||||||
|
{
|
||||||
|
$client->customize();
|
||||||
|
$client->save();
|
||||||
|
} catch (ORM_Validation_Exception $e) {
|
||||||
|
continue;
|
||||||
|
var_dump($client->object());
|
||||||
|
}
|
||||||
|
$client->add('group', $group->id);
|
||||||
}
|
}
|
||||||
$db->commit();
|
$db->commit();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue