示例#1
0
文件: File.php 项目: im286er/ent
 /**
  * 获取密钥信息
  *
  * @param string $project_id            
  * @param string $key_id            
  * @throws \SoapFault
  * @return array
  */
 private function getKeysInfo($project_id, $key_id)
 {
     $query = array();
     $query['project_id'] = $project_id;
     if ($key_id !== null) {
         $query['_id'] = myMongoId($key_id);
     } else {
         $query['default'] = true;
     }
     $query['expire'] = array('$gte' => new \MongoDate());
     $query['active'] = true;
     $rst = $this->_key->findOne($query, array('key' => true));
     if ($rst === null) {
         throw new \Exception(404, '授权密钥无效');
     }
     return $rst;
 }
示例#2
0
 public function keysAction()
 {
     $datas = $this->_keys->findAll(array('expire' => array('$gte' => new \MongoDate(time()), '$lte' => new \MongoDate(time() + 7 * 24 * 3600))));
     $emailContent = '';
     foreach ($datas as $row) {
         $project_id = $row['project_id'];
         $projectInfo = $this->_project->findOne(array('_id' => myMongoId($project_id)));
         if (!empty($projectInfo)) {
             $emailContent .= "项目:“{$projectInfo['name']}”的密钥将于" . date('Y-m-d H:i:s', $row['expire']->sec) . "过期\n";
         }
     }
     if (!empty($emailContent)) {
         sendEmail(array('*****@*****.**', '*****@*****.**'), 'ICC密钥过期提醒', $emailContent);
     }
     echo 'OK';
     return $this->response;
 }
示例#3
0
 /**
  * 删除某项排序
  *
  * @author young
  * @name 删除某项排序
  * @version 2013.11.14 young
  * @return JsonModel
  */
 public function removeAction()
 {
     $_id = $this->params()->fromPost('_id', null);
     try {
         $_id = Json::decode($_id, Json::TYPE_ARRAY);
     } catch (\Exception $e) {
         return $this->msg(false, '无效的json字符串');
     }
     if (!is_array($_id)) {
         return $this->msg(false, '请选择你要删除的项');
     }
     foreach ($_id as $row) {
         $this->_order->remove(array('_id' => myMongoId($row), 'collection_id' => $this->_collection_id));
     }
     return $this->msg(true, '删除信息成功');
 }
示例#4
0
 /**
  * 删除数据集合的索引
  *
  * @author young
  * @name 删除数据集合的索引
  * @version 2013.12.22 young
  */
 public function removeAction()
 {
     $_id = $this->params()->fromPost('_id', null);
     try {
         $_id = Json::decode($_id, Json::TYPE_ARRAY);
     } catch (\Exception $e) {
         return $this->msg(false, '无效的json字符串');
     }
     if (!is_array($_id)) {
         return $this->msg(false, '请选择你要删除的项');
     }
     foreach ($_id as $row) {
         $index = $this->_model->findOne(array('_id' => myMongoId($row)));
         if ($index == null) {
             return $this->msg(false, '无效的索引');
         }
         $keys = Json::decode($index['keys']);
         if (!$this->_targetCollection->deleteIndex($keys)) {
             return $this->msg(false, '删除索引失败');
         }
         $this->_model->remove(array('_id' => myMongoId($row)));
     }
     return $this->msg(true, '删除索引成功');
 }
示例#5
0
 /**
  * 测试结果
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function testAction()
 {
     $statistic_id = $this->params()->fromQuery('statistic_id', null);
     $logError = function ($statisticInfo, $rst) {
         $this->_statistic->update(array('_id' => $statisticInfo['_id']), array('$set' => array('dashboardOut' => '', 'dashboardError' => is_string($rst) ? $rst : Json::encode($rst))));
     };
     $statistics = $this->_statistic->findAll(array('_id' => myMongoId($statistic_id), 'isDashboard' => true));
     if (empty($statistics)) {
         echo 'empty';
         return $this->response;
     }
     foreach ($statistics as $statisticInfo) {
         try {
             if (!empty($statisticInfo['dashboardOut'])) {
                 $oldDashboardOut = $this->collection($statisticInfo['dashboardOut'], DB_MAPREDUCE, DEFAULT_CLUSTER);
                 $oldDashboardOut->physicalDrop();
             }
             // 检查是否存在映射关系
             $mapCollection = $this->_mapping->findOne(array('collection_id' => $statisticInfo['collection_id'], 'active' => true));
             if ($mapCollection != null) {
                 $dataModel = $this->collection()->secondary($mapCollection['collection'], $mapCollection['database'], $mapCollection['cluster']);
             } else {
                 $dataModel = $this->collection()->secondary(iCollectionName($statisticInfo['collection_id']));
             }
             $query = array();
             if (!empty($statisticInfo['dashboardQuery'])) {
                 $query['$and'][] = $statisticInfo['dashboardQuery'];
             }
             $query['$and'][] = array('__CREATE_TIME__' => array('$gte' => new \MongoDate(time() - $statisticInfo['statisticPeriod'])));
             $out = 'dashboard_' . $statisticInfo['_id']->__toString();
             $rst = mapReduce($out, $dataModel, $statisticInfo, $query, 'replace');
             if ($rst instanceof \MongoCollection) {
                 $outCollectionName = $rst->getName();
                 // 输出集合名称
                 $this->_statistic->update(array('_id' => $statisticInfo['_id']), array('$set' => array('dashboardOut' => $outCollectionName, 'lastExecuteTime' => new \MongoDate(), 'resultExpireTime' => new \MongoDate(time() + $statisticInfo['interval']))));
             } else {
                 $logError($statisticInfo, $rst);
             }
             // 替换统计结果中的数据为人可读数据开始
             if (isset($statisticInfo['xAxisType']) && $statisticInfo['xAxisType'] === 'value') {
                 $rshDatas = $this->dealRshData($statisticInfo['project_id'], $statisticInfo['collection_id'], $statisticInfo['xAxisField']);
                 if (!empty($rshDatas)) {
                     try {
                         $rstModel = $this->collection($out, DB_MAPREDUCE, DEFAULT_CLUSTER);
                         $rstModel->setNoAppendQuery(true);
                         $cursor = $rstModel->find(array());
                         while ($cursor->hasNext()) {
                             $row = $cursor->getNext();
                             $rstModel->physicalRemove(array('_id' => $row['_id']));
                             $_id = $row['_id'];
                             $rstModel->update(array('_id' => isset($rshDatas[$_id]) ? $rshDatas[$_id] : $_id), array('$set' => array('value' => $row['value'])), array('upsert' => true));
                         }
                     } catch (\Exception $e) {
                         var_dump($e);
                     }
                 }
             }
             // 替换统计结果中的数据为人可读数据结束
         } catch (\Exception $e) {
             $logError($statisticInfo, $e->getMessage());
         }
     }
     echo 'OK';
     return $this->response;
 }
示例#6
0
 /**
  * 删除集合
  *
  * @author young
  * @name 删除集合
  * @version 2013.11.14 young
  * @return JsonModel
  */
 public function removeAction()
 {
     $_id = $this->params()->fromPost('_id', null);
     $plugin_id = $this->_plugin_id;
     try {
         $_id = Json::decode($_id, Json::TYPE_ARRAY);
     } catch (\Exception $e) {
         return $this->msg(false, '无效的json字符串');
     }
     if (!is_array($_id)) {
         return $this->msg(false, '请选择你要删除的项');
     }
     foreach ($_id as $row) {
         $rowInfo = $this->_collection->findOne(array('_id' => myMongoId($row)));
         if ($rowInfo != null) {
             $this->_plugin_collection->removePluginCollection($this->_project_id, $this->_plugin_id, $rowInfo['alias']);
             $this->_collection->remove(array('_id' => myMongoId($row)));
         }
     }
     return $this->msg(true, '删除信息成功');
 }
示例#7
0
 /**
  * 对于集合进行了任何操作,那么出发联动事件,联动修改其他集合的相关数据
  * 提交全部POST参数以及系统默认的触发参数__TRIGER__
  * $_POST['__TRIGER__']['collection'] 触发事件集合的名称
  * $_POST['__TRIGER__']['controller'] 触发控制器
  * $_POST['__TRIGER__']['action'] 触发动作
  * 为了确保调用安全,签名方法为所有POST参数按照字母顺序排列,构建的字符串substr(sha1(k1=v1&k2=v2连接密钥),0,32),做个小欺骗,让签名看起来很像MD5的。
  */
 public function __destruct()
 {
     fastcgi_finish_request();
     try {
         $controller = $this->params('controller');
         $action = $this->params('action');
         $_POST['__TRIGER__'] = array('collection' => $this->getCollectionAliasById($this->_collection_id), 'controller' => $controller, 'action' => $action);
         $collectionInfo = $this->_collection->findOne(array('_id' => myMongoId($this->_collection_id), 'isAutoHook' => true));
         if ($collectionInfo !== null && isset($collectionInfo['hook']) && filter_var($collectionInfo['hook'], FILTER_VALIDATE_URL) !== false) {
             $sign = dataSignAlgorithm($_POST, $collectionInfo['hookKey']);
             $_POST['__SIGN__'] = $sign;
             $response = doPost($collectionInfo['hook'], $_POST);
             $this->_collection->update(array('_id' => $collectionInfo['_id']), array('$set' => array('hookLastResponseResult' => $response)));
         }
     } catch (\Exception $e) {
         $this->log(exceptionMsg($e));
     }
     return false;
 }
示例#8
0
 /**
  * 同步指定项目的指定插件
  *
  * @param string $project_id
  *            项目编号
  * @param string $plugin_id
  *            插件编号
  * @param string $collectionName
  *            集合名称
  * @return true false
  */
 public function syncPluginCollection($project_id, $plugin_id, $collectionName)
 {
     $pluginCollectionInfo = $this->findOne(array('plugin_id' => $plugin_id, 'alias' => $collectionName));
     if ($pluginCollectionInfo == null) {
         fb('$pluginCollectionInfo is null', 'LOG');
         return false;
     }
     $pluginCollectionInfo['plugin_collection_id'] = isset($pluginCollectionInfo['plugin_collection_id']) ? $pluginCollectionInfo['plugin_collection_id'] : $pluginCollectionInfo['_id']->__toString();
     // 同步数据结构
     $syncPluginStructure = function ($plugin_id, $collection_id) use($pluginCollectionInfo) {
         if ($collection_id instanceof \MongoId) {
             $collection_id = $collection_id->__toString();
         }
         $this->_structure->physicalRemove(array('collection_id' => $collection_id));
         // 插入新的数据结构
         $cursor = $this->_plugin_structure->find(array('plugin_id' => $plugin_id, 'plugin_collection_id' => $pluginCollectionInfo['_id']->__toString()));
         while ($cursor->hasNext()) {
             $row = $cursor->getNext();
             array_unset_recursive($row, array('_id', 'collection_id', '__CREATE_TIME__', '__MODIFY_TIME__', '__REMOVED__'));
             $row['collection_id'] = $collection_id;
             $this->_structure->update(array('collection_id' => $collection_id, 'field' => $row['field']), array('$set' => $row), array('upsert' => true));
         }
         // 插入新的数据
         if (isset($pluginCollectionInfo['_id']) && $pluginCollectionInfo['_id'] instanceof \MongoId) {
             $plugin_collection_id = $pluginCollectionInfo['_id']->__toString();
             $target_collection_id = $collection_id;
             $this->_plugin_data->copy($plugin_collection_id, $target_collection_id);
         }
         return true;
     };
     // 添加映射关系
     $createMapping = function ($collection_id, $collectionName) use($project_id, $plugin_id) {
         if ($collection_id instanceof \MongoId) {
             $collection_id = $collection_id->__toString();
         }
         $projectPluginInfo = $this->_project_plugin->findOne(array('project_id' => $project_id, 'plugin_id' => $plugin_id));
         if ($projectPluginInfo !== null) {
             $source_project_id = $projectPluginInfo['source_project_id'];
             if (!empty($source_project_id)) {
                 $collectionInfo = $this->_collection->findOne(array('project_id' => $source_project_id, 'plugin_id' => $plugin_id, 'alias' => $collectionName));
                 $this->_mapping->update(array('project_id' => $project_id, 'collection_id' => $collection_id), array('$set' => array('collection' => 'idatabase_collection_' . myMongoId($collectionInfo['_id']), 'database' => DEFAULT_DATABASE, 'cluster' => DEFAULT_CLUSTER, 'active' => true)), array('upsert' => true));
                 return true;
             }
         }
         return false;
     };
     if ($pluginCollectionInfo != null) {
         unset($pluginCollectionInfo['_id']);
         $collectionInfo = $pluginCollectionInfo;
         $collectionInfo['project_id'] = array($project_id);
         $check = $this->_collection->findOne(array('project_id' => $project_id, 'alias' => $collectionName));
         array_unset_recursive($collectionInfo, array('isAutoHook', 'hook', 'hookKey'));
         if ($check == null) {
             $this->_collection->insertRef($collectionInfo);
             $syncPluginStructure($plugin_id, $collectionInfo['_id']);
             $createMapping($collectionInfo['_id'], $collectionName);
             return $collectionInfo;
         } else {
             $this->_collection->update(array('_id' => $check['_id']), array('$set' => $collectionInfo));
             $syncPluginStructure($plugin_id, $check['_id']);
             $createMapping($check['_id'], $collectionName);
         }
         // 同步默认数据,默认数据将覆盖原有数据
         return $check;
     }
     return false;
 }
示例#9
0
 /**
  * 复制一个项目
  */
 public function cloneAction()
 {
     try {
         $projectId = $this->params()->fromQuery("projectId", '');
         $targetProjectId = $this->params()->fromQuery("targetProjectId", '');
         // 获取复制项目表
         $source_formIds = $this->params()->fromQuery('forms', array());
         // 是否复制数据
         $isCopyData = intval($this->params()->fromQuery("isCopyData", 0));
         // 是否是同一个数据库
         $isSameProject = $projectId == $targetProjectId;
         if (!empty($projectId)) {
             $projectInfo = $this->_project->findOne(array('_id' => myMongoId($projectId)));
             if (empty($projectInfo)) {
                 return $this->msg(false, '源项目不存在,无法复制');
             }
             $checkProject = $this->_project->findOne(array('_id' => myMongoId($targetProjectId)));
             if (empty($checkProject)) {
                 return $this->msg(false, '目标项目不存在,无法复制');
             }
             resetTimeMemLimit();
             // 获取该项目下的所有表,循环复制
             $formIds = array();
             $query = array();
             $query['projectId'] = $projectId;
             if (count($source_formIds) > 0) {
                 foreach ($source_formIds as $k => &$v) {
                     $v = myMongoId($v);
                 }
             }
             $query['_id'] = array('$in' => $source_formIds);
             $collection = $this->model('Idatabase\\Model\\Collection');
             $cursor = $collection->find($query);
             while ($cursor->hasNext()) {
                 $formInfo = $cursor->getNext();
                 // 复制表
                 $newFormInfo = $this->cloneForm($targetProjectId, $formInfo, $isCopyData);
                 // 返回旧表的ID和新表ID的对应数组
                 $formIds[$formInfo['_id']->__toString()] = $newFormInfo['newFormID'];
             }
             // 更新结构表的外键关联信息及数据关系
             $this->updateRshDataForm($formIds);
             return $this->msg(true, '复制项目成功');
         } else {
             return $this->msg(false, '请提交你要复制的项目');
         }
     } catch (\Exception $e) {
         $exceptMsg = exceptionMsg($e);
         return $this->msg(false, $exceptMsg);
     }
 }
示例#10
0
文件: Database.php 项目: im286er/ent
 /**
  * 设定集合名称,请在SOAP HEADER部分进行设定
  *
  * @param string $collectionAlias            
  * @throws \SoapFault
  * @return bool
  */
 public function setCollection($collectionAlias)
 {
     $this->_collection = new MongoCollection($this->_config, IDATABASE_COLLECTIONS);
     $this->_mapping = new MongoCollection($this->_config, IDATABASE_MAPPING);
     $collectionInfo = $this->_collection->findOne(array('project_id' => $this->_project_id, 'alias' => $collectionAlias));
     if ($collectionInfo === null) {
         throw new \SoapFault(404, '访问集合不存在');
     }
     $this->_collection_id = myMongoId($collectionInfo['_id']);
     $mapping = $this->_mapping->findOne(array('project_id' => $this->_project_id, 'collection_id' => $this->_collection_id, 'active' => true));
     if ($mapping === null) {
         $this->_model = new MongoCollection($this->_config, iCollectionName($this->_collection_id));
     } else {
         $this->_model = new MongoCollection($this->_config, $mapping['collection'], $mapping['database'], $mapping['cluster']);
     }
     $this->getSchema();
     return true;
 }