示例#1
0
 /**
  * @brief Deletes all addressbooks of a certain user
  * @param parameters parameters from postDeleteUser-Hook
  * @return array
  */
 public static function deleteUser($parameters)
 {
     \OCP\Util::writeLog('contactsplus', 'Hook DEL ID-> ' . $parameters['uid'], \OCP\Util::DEBUG);
     $addressbooks = Addressbook::all($parameters['uid']);
     foreach ($addressbooks as $addressbook) {
         if ($parameters['uid'] === $addressbook['userid']) {
             Addressbook::delete($addressbook['id']);
         }
     }
     //delete preferences
     return true;
 }
示例#2
0
 /**
  * @NoAdminRequired
  */
 public function importVcards()
 {
     $pProgresskey = $this->params('progresskey');
     $pGetprogress = $this->params('getprogress');
     $pPath = $this->params('path');
     $pFile = $this->params('file');
     $pMethod = $this->params('method');
     $pAddressbook = $this->params('addressbookname');
     $pIsDragged = $this->params('isDragged');
     $pId = $this->params('id');
     $pOverwrite = $this->params('overwrite');
     \OC::$server->getSession()->close();
     if (isset($pProgresskey) && isset($pGetprogress)) {
         $aCurrent = \OC::$server->getCache()->get($pProgresskey);
         $aCurrent = json_decode($aCurrent);
         $numVC = isset($aCurrent->{'all'}) ? $aCurrent->{'all'} : 0;
         $currentVCCount = isset($aCurrent->{'current'}) ? $aCurrent->{'current'} : 0;
         $currentFn = isset($aCurrent->{'currentFn'}) ? $aCurrent->{'currentFn'} : '';
         $percent = isset($aCurrent->{'percent'}) ? $aCurrent->{'percent'} : '';
         if ($percent == '') {
             $percent = 0;
         }
         $params = ['status' => 'success', 'percent' => $percent, 'currentmsg' => $currentFn . ' ' . $percent . '% (' . $currentVCCount . '/' . $numVC . ')'];
         $response = new JSONResponse($params);
         return $response;
     }
     if ($pIsDragged === 'true') {
         //OCP\JSON::error(array('error'=>'404'));
         $file = explode(',', $pFile);
         $file = end($file);
         $file = base64_decode($file);
     } else {
         $file = \OC\Files\Filesystem::file_get_contents($pPath . '/' . $pFile);
     }
     if (!$file) {
         $params = ['status' => 'error', 'error' => '404'];
         $response = new JSONResponse($params);
         return $response;
     }
     $file = \Sabre\VObject\StringUtil::convertToUTF8($file);
     $import = new Import($file);
     $import->setUserID($this->userId);
     $import->setProgresskey($pProgresskey);
     $import->enableProgressCache();
     \OCP\Util::writeLog($this->appName, ' PROG: ' . $pProgresskey, \OCP\Util::DEBUG);
     if (!$import->isValid()) {
         $params = ['status' => 'error', 'error' => 'notvalid'];
         $response = new JSONResponse($params);
         return $response;
     }
     $newAddressbook = false;
     if ($pMethod == 'new') {
         $id = Addressbook::add($this->userId, $pAddressbook);
         if ($id) {
             Addressbook::setActive($id, 1);
             $newAddressbook = true;
         }
     } else {
         $id = $pId;
         Addressbook::find($id);
         $import->setOverwrite($pOverwrite);
     }
     //\OCP\Util::writeLog($this->appName,' METHOD: '.$pMethod.'ID:'.$id, \OCP\Util::DEBUG);
     $import->setAddressbookId($id);
     try {
         $import->import();
     } catch (\Exception $e) {
         $params = ['status' => 'error', 'message' => $this->l10n->t('Import failed')];
         $response = new JSONResponse($params);
         return $response;
     }
     $count = $import->getCount();
     $errorCount = $import->getErrorCount();
     if ($count == 0) {
         if ($newAddressbook) {
             Addressbook::delete($id);
         }
         $params = ['status' => 'error', 'message' => $this->l10n->t('The file contained either no vcard or all vcards are already saved in your addessbook.')];
         $response = new JSONResponse($params);
         return $response;
     } else {
         if ($newAddressbook) {
             $params = ['status' => 'success', 'message' => $count . ' ' . $this->l10n->t('vcards has been saved in the new addressbook') . ' ' . strip_tags($pAddressbook)];
             $response = new JSONResponse($params);
             return $response;
         } else {
             $params = ['status' => 'success', 'message' => $errorCount . ' Error - ' . $count . ' ' . $this->l10n->t('vcards has been saved in your addressbook')];
             $response = new JSONResponse($params);
             return $response;
         }
     }
 }
示例#3
0
 /**
  * Deletes an entire addressbook and all its contents
  *
  * @param int $addressbookid
  * @return void
  */
 public function deleteAddressBook($addressbookid)
 {
     AddrBook::delete($addressbookid);
 }
 /**
  * @NoAdminRequired
  */
 public function delete()
 {
     $pId = $this->params('id');
     if (!$pId) {
         $msg = (string) $this->l10n->t('id is not set.');
     }
     try {
         Addressbook::delete($pId);
     } catch (Exception $e) {
         //bailOut($e->getMessage());
     }
     $params = ['status' => 'success', 'data' => ['id' => $pId]];
     $response = new JSONResponse($params);
     return $response;
 }