Example #1
0
 /**
  * @overrides get() from RestResource
  */
 public function get()
 {
     if (parent::get() !== false) {
         $results = array();
         $handle = @opendir(RestAPIHelper::getFolder(RestFolderEnum::FE_XSD_FOLDER));
         if ($handle) {
             while (false !== ($file = readdir($handle))) {
                 if ($file != "." && $file != ".." && substr($file, strlen($file) - strlen("xsd")) == "xsd") {
                     $results[] = "<appdb:schema name='" . str_replace(".xsd", "", $file) . "' uri='http://" . $_SERVER["APPLICATION_API_HOSTNAME"] . "/rest/" . RestAPIHelper::getVersion() . "/schema/" . str_replace(".xsd", "", $file) . "'/>";
                 }
             }
             closedir($handle);
         }
         $this->_pageOffset = 0;
         $this->_pageLength = count($results);
         $this->_total = count($results);
         return new XMLFragmentRestResponse($results, $this);
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * realization of logAction() from iRestAPILogger.
  */
 public function logAction($event, $target, $id, $old, $new, $disposition = null)
 {
     if ($this->_logfile != '') {
         if (strval($old) != strval($new)) {
             $now = new DateTime();
             $f = fopen($this->_logfile, "a");
             if ($f !== false) {
                 error_log('Acquiring exclusive lock on logfile "' . $this->_logfile . '"');
                 if (flock($f, LOCK_EX)) {
                     $userid = $this->_userid != "" ? ' userid="' . $this->_userid . '"' : '';
                     $username = $this->_userid != "" ? ' username="******"' : '';
                     $usercontact = $this->_userid != "" ? is_null($this->getUser()->primaryContact) ? '' : ' usercontact="' . $this->getUser()->primaryContact . '"' : '';
                     $dispo = $disposition === null ? "" : ' disposition="' . $disposition . '"';
                     fwrite($f, '<action target="' . $target . '" id="' . $id . '" event="' . $event . '"' . $userid . $username . $usercontact . $dispo . ' apiver="' . RestAPIHelper::getVersion() . '" timestamp="' . $now->format('Ydm H:i:s') . '">' . "\n");
                     if ($old != "") {
                         fwrite($f, '<oldvalue>' . base64_encode(bzcompress($old)) . '</oldvalue>' . "\n");
                     }
                     if ($new != "") {
                         fwrite($f, '<newvalue>' . base64_encode(bzcompress($new)) . '</newvalue>' . "\n");
                     }
                     fwrite($f, '</action>' . "\n");
                     flock($f, LOCK_UN);
                     fclose($f);
                 } else {
                     error_log('Could not acquire exclusive write log for logfile "' . $this->_logfile . '". Will not log API action.');
                 }
             } else {
                 error_log('Could not write API log entry in logfile "' . $this->_logfile . '"');
             }
         }
     }
 }