Skip to content

Instantly share code, notes, and snippets.

@davegardnerisme
Created May 18, 2012 10:13
Show Gist options
  • Select an option

  • Save davegardnerisme/2724446 to your computer and use it in GitHub Desktop.

Select an option

Save davegardnerisme/2724446 to your computer and use it in GitHub Desktop.
try
{
$diContainer = new diContainer();
$cassandra = $diContainer->getInstance('vdna_service_cassandra');
$locksmith = $diContainer->getInstance('vdna_service_locksmith');
$userDao = $diContainer->getInstance('vdna_dao_user_interface');
// ---
$finished = FALSE;
$startKey = '';
$endKey = '';
$batchCount = 100;
while (!$finished)
{
try
{
$rows = $cassandra->getRows(
'activeEmailUsers',
$startKey,
$endKey,
$batchCount
);
// first ever time, increment batch count, to take into account
// start row duplication
if (empty($startKey))
{
$batchCount++;
}
else
{
// not first; strip off first row
array_shift($rows);
}
// any?
if (!empty($rows))
{
foreach ($rows as $keySlice)
{
$userUuid = $keySlice->key;
try
{
$user = $userDao->getById($userUuid);
if ($user->canBeEmailed())
{
// cool; valid user
echo $userUuid . "\t" . $user->getEmailAddress() . "\n";
}
}
catch (vdna_error_notFound $e)
{
$user = NULL;
}
} // end foreach rows
end($rows);
list($id,$keySlice) = each($rows);
$startKey = $keySlice->key;
}
else
{
$finished = TRUE;
}
}
catch (vdna_error_notFound $e)
{
$finished = TRUE;
$e = NULL;
}
}
}
catch (Exception $e)
{
echo "\n\033[37;41mEPIC FAIL: ".(string)$e."\033[0m\n\n";
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment