Swiftriver\Core\Modules\DataContext\Mongo_V1\DataContext::SaveChannels PHP Method

SaveChannels() public static method

Adds a list of new Channels to the data store
public static SaveChannels ( $channels )
    public static function SaveChannels($channels)
    {
        $logger = \Swiftriver\Core\Setup::GetLogger();
        $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [Method Invoked]", \PEAR_LOG_DEBUG);
        $db = self::MongoDatabase();
        if (!\is_array($channels) || count($channels) < 1) {
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [No channels supplied]", \PEAR_LOG_DEBUG);
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [Method finished]", \PEAR_LOG_DEBUG);
            return;
        }
        try {
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [START: Looping through channels]", \PEAR_LOG_DEBUG);
            foreach ($channels as $channel) {
                $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [START: Executing PDO statement for channel]", \PEAR_LOG_DEBUG);
                $exists_result = $db->get_where("channels", array("id" => $channel->id));
                $result = null;
                if (count($exists_result) > 0) {
                    $db->where("id", $channel->id);
                    $result = $db->update("channels", array("name" => $channel->name, "type" => $channel->type, "subType" => $channel->subType, "active" => $channel->active, "inprocess" => $channel->inprocess, "nextRun" => $channel->nextrun, "timesrun" => $channel->timesrun, "updatePeriod" => $channel->updatePeriod, "lastSuccess" => $channel->lastSuccess, "deleted" => $channel->deleted, "trusted" => $channel->trusted, "parameters" => $channel->parameters));
                    $db->where(array());
                } else {
                    $result = $db->insert("channels", array("id" => $channel->id, "name" => $channel->name, "type" => $channel->type, "subType" => $channel->subType, "active" => $channel->active, "inprocess" => $channel->inprocess, "nextRun" => $channel->nextrun, "timesrun" => $channel->timesrun, "updatePeriod" => $channel->updatePeriod, "lastSuccess" => $channel->lastSuccess, "deleted" => $channel->deleted, "trusted" => $channel->trusted, "parameters" => $channel->parameters));
                }
                if ($result === FALSE) {
                    $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [An Exception was thrown by the Mongo DB framwork]", \PEAR_LOG_ERR);
                    $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [Could not insert a new channel into the Mongo Collection]", \PEAR_LOG_ERR);
                }
                $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [END: Executing PDO statement for channel]", \PEAR_LOG_DEBUG);
            }
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [END: Looping through channels]", \PEAR_LOG_DEBUG);
            $db = null;
        } catch (\MongoException $e) {
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [An exception was thrown]", \PEAR_LOG_ERR);
            $logger->log("Core::Modules::DataContext::Mongo_V1::DataContext::SaveChannels [{$e}]", \PEAR_LOG_ERR);
        }
    }