honour service class restrictions for total_identities, total_channels ("friends") and total_feeds both when importing channels and subsequently when syncing clones. Limits are based on the local system - additional entries are silently dropped.

This commit is contained in:
friendica
2014-09-15 17:17:00 -07:00
parent c841714ba5
commit bbc9e4427e
3 changed files with 87 additions and 5 deletions

View File

@@ -9,10 +9,25 @@ require_once('include/identity.php');
function import_post(&$a) {
if(! get_account_id()) {
$account_id = get_account_id();
if(! $account_id)
return;
$max_identities = account_service_class_fetch($account_id,'total_identities');
$max_friends = account_service_class_fetch($account_id,'total_channels');
$max_feeds = account_service_class_fetch($account_id,'total_feeds');
if($max_identities !== false) {
$r = q("select channel_id from channel where channel_account_id = %d",
intval($account_id)
);
if($r && count($r) > $max_identities) {
notice( sprintf( t('Your service plan only allows %d channels.'), $max_identities) . EOL);
return;
}
}
$data = null;
$seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);
@@ -276,10 +291,18 @@ function import_post(&$a) {
// FIXME - ensure we have an xchan if somebody is trying to pull a fast one
$friends = 0;
$feeds = 0;
// import contacts
$abooks = $data['abook'];
if($abooks) {
foreach($abooks as $abook) {
if($max_friends !== false && $friends > $max_friends)
continue;
if($max_feeds !== false && ($abook['abook_flags'] & ABOOK_FLAG_FEED) && $feeds > $max_feeds)
continue;
unset($abook['abook_id']);
$abook['abook_account'] = get_account_id();
$abook['abook_channel'] = $channel['channel_id'];
@@ -289,6 +312,10 @@ function import_post(&$a) {
. "`) VALUES ('"
. implode("', '", array_values($abook))
. "')" );
$friends ++;
if($abook['abook_flags'] & ABOOK_FLAG_FEED)
$feeds ++;
}
}