Пример #1
0
 private function validateInputParamsForUpload(&$p)
 {
     if (!isset($p['pid'])) {
         return 'pid not specified';
     }
     if (!is_numeric($p['pid'])) {
         return 'pid not valid';
     }
     if (empty($p['template_id']) && !empty($p['tmplId'])) {
         $p['template_id'] = $p['tmplId'];
     }
     if (empty($p['template_id'])) {
         $p['template_id'] = \CB\Config::get('default_file_template');
         if (empty($p['template_id'])) {
             return 'template not specified';
         }
     }
     if (!empty($p['fileExistAction'])) {
         if (!in_array($p['fileExistAction'], array('newversion', 'replace', 'autorename'))) {
             return 'Invalid value for fileExistAction';
         }
         $p['response'] = $p['fileExistAction'];
         unset($p['fileExistAction']);
     }
     if (!is_numeric($p['template_id'])) {
         return 'template id not valid';
     }
     if (!empty($p['localFile'])) {
         if (!file_exists($p['localFile'])) {
             return 'File not found: ' . $p['localFile'];
         }
     } else {
         if (empty($_FILES)) {
             return 'No file found for upload';
         }
     }
     if (empty($p['title'])) {
         if (!empty($p['filename'])) {
             $p['title'] = $p['filename'];
             unset($p['filename']);
         } else {
             if (!empty($p['localFile'])) {
                 $p['title'] = basename($p['localFile']);
             } elseif (!empty($_FILES['file'])) {
                 $p['title'] = $_FILES['file']['name'];
             }
         }
     }
     if (empty($p['title'])) {
         return 'Cannot detect file title';
     }
     if (!isset($p['oid'])) {
         if (!isset($p['owner'])) {
             return 'owner not specified';
         }
         if (is_numeric($p['owner'])) {
             if (DM\User::idExists($p['owner'])) {
                 $p['oid'] = $p['owner'];
             }
         } else {
             $p['oid'] = DM\User::getIdByName($p['owner']);
         }
     }
     if (!is_numeric($p['oid'])) {
         return 'invalid owner specified';
     } elseif (empty($p['cid'])) {
         $p['cid'] = $p['oid'];
     }
     return true;
 }
Пример #2
0
 public function testIdExists()
 {
     $id = DM\User::toId($this->testName);
     $this->assertTrue(DM\User::idExists($id), 'Id doesnt exist');
     $this->assertTrue(!DM\User::idExists(-$id), 'Id exist');
 }