Example #1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->asfGuardUser !== null) {
             if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
                 $affectedRows += $this->asfGuardUser->save($con);
             }
             $this->setsfGuardUser($this->asfGuardUser);
         }
         if ($this->aRepository !== null) {
             if ($this->aRepository->isModified() || $this->aRepository->isNew()) {
                 $affectedRows += $this->aRepository->save($con);
             }
             $this->setRepository($this->aRepository);
         }
         if ($this->aBranch !== null) {
             if ($this->aBranch->isModified() || $this->aBranch->isNew()) {
                 $affectedRows += $this->aBranch->save($con);
             }
             $this->setBranch($this->aBranch);
         }
         if ($this->aFile !== null) {
             if ($this->aFile->isModified() || $this->aFile->isNew()) {
                 $affectedRows += $this->aFile->save($con);
             }
             $this->setFile($this->aFile);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aFeaturevector !== null) {
             if ($this->aFeaturevector->isModified() || $this->aFeaturevector->isNew()) {
                 $affectedRows += $this->aFeaturevector->save($con);
             }
             $this->setFeaturevector($this->aFeaturevector);
         }
         if ($this->aFile !== null) {
             if ($this->aFile->isModified() || $this->aFile->isNew()) {
                 $affectedRows += $this->aFile->save($con);
             }
             $this->setFile($this->aFile);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = FeaturevectorsegmentPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += FeaturevectorsegmentPeer::doUpdate($this, $con);
             }
             // Rewind the data LOB column, since PDO does not rewind after inserting value.
             if ($this->data !== null && is_resource($this->data)) {
                 rewind($this->data);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Save a file. The new file have an extension like ".new", and is saved in the same folder as the original.
  * 
  * @HERE : The new file no more have an extension '.new'. Now, it's saved into 'module-name-'new folder, with the same folder's hierarchie
  *
  *
  */
 public function saveFile()
 {
     $am = AccountManager::getInstance();
     $tx = new ToolsXmllint();
     if (!$am->isLogged()) {
         return JsonResponseBuilder::failure();
     }
     $filePath = $this->getRequestVariable('filePath');
     $fileName = $this->getRequestVariable('fileName');
     $fileLang = $this->getRequestVariable('fileLang');
     $type = $this->hasRequestVariable('type') ? $this->getRequestVariable('type') : 'file';
     $emailAlert = $this->hasRequestVariable('emailAlert') ? $this->getRequestVariable('emailAlert') : '';
     // Clean up path
     $filePath = str_replace('//', '/', $filePath);
     // Extract lang from path
     if ($fileLang == 'all') {
         $t = explode('/', $filePath);
         $fileLang = $t[0];
         array_shift($t);
         $filePath = '/' . implode('/', $t);
     }
     // Remove \
     $fileContent = $this->getRequestVariable('fileContent');
     // Replace   by space
     $fileContent = str_replace(" ", "", $fileContent);
     // We check the Xml consistence only for .xml file
     if (substr($fileName, -3) == 'xml') {
         $xmlError = $tx->checkForError($fileContent);
         if ($xmlError != 'no_error') {
             return JsonResponseBuilder::failure(array('XmlError' => $xmlError));
         }
     }
     // Get file object
     $file = new File($fileLang, $filePath . $fileName);
     // Rules to allow this file to be saved or not.
     if ($infoModified = $file->isModified()) {
         $infoModified = json_decode($infoModified);
         // If the user who have modified this file isn't the current one
         if ($am->userID == $infoModified->userID) {
             // We can modify it, it's mine ;)
         } else {
             // If the current user have karma, he can modify it.
             if ($am->haveKarma) {
                 // The current user can modify it
             } else {
                 // We must trow an error. We can't modify it.
                 return JsonResponseBuilder::failure(array('type' => 'save_you_cant_modify_it'));
             }
         }
     }
     // Detect encoding
     $charset = $file->getEncoding($fileContent);
     // If the new charset is set to utf-8, we don't need to decode it
     if ($charset != 'utf-8') {
         $fileContent = iconv("UTF-8", $charset, $fileContent);
     }
     // We detect tab caracters and trow an error if we find one.
     if (strstr("\t", $fileContent)) {
         return JsonResponseBuilder::failure(array('type' => 'tabs_found'));
     }
     // Get revision
     $info = $file->getInfo($fileContent);
     if ($type == 'file') {
         $er = $file->save($fileContent);
         $isError = is_array($er) && empty($er['state']);
         if (!$isError) {
             $r = RepositoryManager::getInstance()->addProgressWork($file, $info['rev'], $info['en-rev'], $info['reviewed'], $info['reviewed_maintainer'], $info['maintainer']);
             return JsonResponseBuilder::success(array('id' => $r, 'lang' => $fileLang, 'revision' => $info['rev'], 'en_revision' => $info['en-rev'], 'maintainer' => $info['maintainer'], 'reviewed' => $info['reviewed'], 'reviewed_maintainer' => $info['reviewed_maintainer']));
         } else {
             return JsonResponseBuilder::failure(array('type' => 'fs_error'));
         }
     } else {
         if ($type == 'trans') {
             // We must ensure that this folder exist localy
             if ($file->folderExist()) {
                 $er = $file->save($fileContent);
                 if ($er['state']) {
                     $r = RepositoryManager::getInstance()->addProgressWork($file, $info['rev'], $info['en-rev'], $info['reviewed'], $info['reviewed_maintainer'], $info['maintainer'], 'new');
                     return JsonResponseBuilder::success(array('id' => $r, 'lang' => $fileLang, 'revision' => $info['rev'], 'en_revision' => $info['en-rev'], 'maintainer' => $info['maintainer'], 'reviewed' => $info['reviewed'], 'reviewed_maintainer' => $info['reviewed_maintainer']));
                 } else {
                     return JsonResponseBuilder::failure(array('type' => 'fs_error'));
                 }
             } else {
                 return JsonResponseBuilder::failure();
             }
         }
     }
 }