DB migration for instants (sent flag)

This commit is contained in:
Alexander Yakovlev 2014-02-18 14:45:48 +07:00
parent 993a4a600d
commit f421dc7884
4 changed files with 35 additions and 16 deletions

View File

@ -71,20 +71,4 @@ class Model_Instant extends ORM {
}
return $email->send();
}
/**
* Send the instant to all subscribers if it's not a draft
**/
public function save()
{
if (!$this->is_draft())
{
$subscription = ORM::factory('Subscription', $this->subscription_id);
$subscribers = $subscription->clients->find_all();
foreach ($subscribers as $subscriber)
{
}
}
}
}

View File

@ -50,4 +50,12 @@ class Model_Subscription extends ORM {
'welcome' => 'Welcome message',
'description' => 'Description (for the clients)'
);
/**
* Return subscriber count
**/
public function count_clients()
{
return DB::select(array(DB::expr('COUNT(client_id)'), 'cnt'))->from('clients_courses')->where('course_id', '=', $this->id)->execute()->get('cnt');
}
}

View File

@ -0,0 +1,27 @@
<?php defined('SYSPATH') OR die('No direct script access.');
class Migration_Kangana_20140218143726 extends Minion_Migration_Base {
/**
* Run queries needed to apply this migration
*
* @param Kohana_Database $db Database connection
*/
public function up(Kohana_Database $db)
{
$db->query(NULL, 'alter table `instants` drop column `is_draft`');
$db->query(NULL, "alter table `instants` add column `sent` int(1) not null default '0'");
}
/**
* Run queries needed to remove this migration
*
* @param Kohana_Database $db Database connection
*/
public function down(Kohana_Database $db)
{
$db->query(NULL, 'alter table `instants` drop column `sent`');
$db->query(NULL, "alter table `instants` add column `is_draft` int(1) not null default '1'");
}
}

BIN
model.mwb

Binary file not shown.