/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Add a tag for each label $tags = array(); if ($this->show_full) { for ($i = 1; $i < 4; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tags[] = IDF_Tag::add($name, $this->project, $class); } } } // Create the page $page = new IDF_WikiPage(); $page->project = $this->project; $page->submitter = $this->user; $page->summary = trim($this->cleaned_data['summary']); $page->title = trim($this->cleaned_data['title']); $page->create(); foreach ($tags as $tag) { $page->setAssoc($tag); } // add the first revision $rev = new IDF_WikiRevision(); $rev->wikipage = $page; $rev->content = $this->cleaned_data['content']; $rev->submitter = $this->user; $rev->summary = __('Initial page creation'); $rev->create(); $rev->notify($this->project->getConf()); return $page; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Add a tag for each label $tags = array(); for ($i = 1; $i < 7; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tags[] = IDF_Tag::add($name, $this->project, $class); } } // Create the upload $upload = new IDF_Upload(); $upload->project = $this->project; $upload->submitter = $this->user; $upload->summary = trim($this->cleaned_data['summary']); $upload->changelog = trim($this->cleaned_data['changelog']); $upload->file = $this->cleaned_data['file']; $upload->filesize = filesize(Pluf::f('upload_path') . '/' . $this->project->shortname . '/files/' . $this->cleaned_data['file']); $upload->downloads = 0; $upload->create(); foreach ($tags as $tag) { $upload->setAssoc($tag); } // Send the notification $upload->notify($this->project->getConf()); /** * [signal] * * IDF_Upload::create * * [sender] * * IDF_Form_Upload * * [description] * * This signal allows an application to perform a set of tasks * just after the upload of a file and after the notification run. * * [parameters] * * array('upload' => $upload); * */ $params = array('upload' => $upload); Pluf_Signal::send('IDF_Upload::create', 'IDF_Form_Upload', $params); return $upload; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } if ($this->show_full) { // Add a tag for each label $tags = array(); $tagids = array(); for ($i = 1; $i < 7; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tag = IDF_Tag::add($name, $this->project, $class); $tags[] = $tag; $tagids[] = $tag->id; } } // Compare between the old and the new data $changes = array(); $oldtags = $this->issue->get_tags_list(); foreach ($tags as $tag) { if (!Pluf_Model_InArray($tag, $oldtags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = (string) $tag; //new tag } else { $changes['lb'][] = (string) $tag->name; } } } foreach ($oldtags as $tag) { if (!Pluf_Model_InArray($tag, $tags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = '-' . (string) $tag; //new tag } else { $changes['lb'][] = '-' . (string) $tag->name; } } } // Status, summary and owner $status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status'); if ($status->id != $this->issue->status) { $changes['st'] = $status->name; } if (trim($this->issue->summary) != trim($this->cleaned_data['summary'])) { $changes['su'] = trim($this->cleaned_data['summary']); } $owner = self::findUser($this->cleaned_data['owner']); if (is_null($owner) and !is_null($this->issue->get_owner()) or !is_null($owner) and is_null($this->issue->get_owner()) or !is_null($owner) and !is_null($this->issue->get_owner()) and $owner->id != $this->issue->get_owner()->id) { $changes['ow'] = is_null($owner) ? '---' : $owner->login; } // Update the issue $this->issue->batchAssoc('IDF_Tag', $tagids); $this->issue->summary = trim($this->cleaned_data['summary']); $this->issue->status = $status; $this->issue->owner = $owner; } // Create the comment $comment = new IDF_IssueComment(); $comment->issue = $this->issue; $comment->content = $this->cleaned_data['content']; $comment->submitter = $this->user; if (!$this->show_full) { $changes = array(); } $comment->changes = $changes; $comment->create(); $this->issue->update(); if ($this->issue->owner != $this->user->id and $this->issue->submitter != $this->user->id) { $this->issue->setAssoc($this->user); // interested user. } $attached_files = array(); for ($i = 1; $i < 4; $i++) { if ($this->cleaned_data['attachment' . $i]) { $file = new IDF_IssueFile(); $file->attachment = $this->cleaned_data['attachment' . $i]; $file->submitter = $this->user; $file->comment = $comment; $file->create(); $attached_files[] = $file; } } /** * [signal] * * IDF_Issue::update * * [sender] * * IDF_Form_IssueUpdate * * [description] * * This signal allows an application to perform a set of tasks * just after the update of an issue. * * [parameters] * * array('issue' => $issue, * 'comment' => $comment, * 'files' => $attached_files); * */ $params = array('issue' => $this->issue, 'comment' => $comment, 'files' => $attached_files); Pluf_Signal::send('IDF_Issue::update', 'IDF_Form_IssueUpdate', $params); return $this->issue; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // create a base comment $bc = new IDF_Review_Comment(); $bc->patch = $this->patch; $bc->submitter = $this->user; $bc->content = $this->cleaned_data['content']; $review = $this->patch->get_review(); if ($this->show_full) { // Compare between the old and the new data // Status, summary $changes = array(); $status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status'); if ($status->id != $this->patch->get_review()->status) { $changes['st'] = $status->name; } if (trim($this->patch->get_review()->summary) != trim($this->cleaned_data['summary'])) { $changes['su'] = trim($this->cleaned_data['summary']); } // Update the review $review->summary = trim($this->cleaned_data['summary']); $review->status = $status; $bc->changes = $changes; } $bc->create(); foreach ($this->files as $filename => $def) { if (!empty($this->cleaned_data[md5($filename)])) { // Add a comment. $c = new IDF_Review_FileComment(); $c->comment = $bc; $c->cfile = $filename; $c->content = $this->cleaned_data[md5($filename)]; $c->create(); } } $review->update(); // reindex and put up in the list. return $bc; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Add a tag for each label $tags = array(); if ($this->show_full) { for ($i = 1; $i < 7; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tags[] = IDF_Tag::add($name, $this->project, $class); } } } else { $tags[] = IDF_Tag::add('Medium', $this->project, 'Priority'); $tags[] = IDF_Tag::add('Defect', $this->project, 'Type'); } // Create the issue $issue = new IDF_Issue(); $issue->project = $this->project; $issue->submitter = $this->user; if ($this->show_full) { $issue->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status'); $issue->owner = self::findUser($this->cleaned_data['owner']); } else { $_t = $this->project->getTagIdsByStatus('open'); $issue->status = new IDF_Tag($_t[0]); // first one is the default $issue->owner = null; } $issue->summary = trim($this->cleaned_data['summary']); $issue->create(); foreach ($tags as $tag) { $issue->setAssoc($tag); } // add the first comment $comment = new IDF_IssueComment(); $comment->issue = $issue; $comment->content = $this->cleaned_data['content']; $comment->submitter = $this->user; $comment->create(); // If we have a file, create the IDF_IssueFile and attach // it to the comment. $created_files = array(); for ($i = 1; $i < 4; $i++) { if ($this->cleaned_data['attachment' . $i]) { $file = new IDF_IssueFile(); $file->attachment = $this->cleaned_data['attachment' . $i]; $file->submitter = $this->user; $file->comment = $comment; $file->create(); $created_files[] = $file; } } /** * [signal] * * IDF_Issue::create * * [sender] * * IDF_Form_IssueCreate * * [description] * * This signal allows an application to perform a set of tasks * just after the creation of an issue. The comment contains * the description of the issue. * * [parameters] * * array('issue' => $issue, * 'comment' => $comment, * 'files' => $attached_files); * */ $params = array('issue' => $issue, 'comment' => $comment, 'files' => $created_files); Pluf_Signal::send('IDF_Issue::create', 'IDF_Form_IssueCreate', $params); return $issue; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Create the review $review = new IDF_Review(); $review->project = $this->project; $review->summary = $this->cleaned_data['summary']; $review->submitter = $this->user; if (!isset($this->cleaned_data['status'])) { $this->cleaned_data['status'] = 'New'; } $review->status = IDF_Tag::add(trim($this->cleaned_data['status']), $this->project, 'Status'); $review->create(); // add the first patch $patch = new IDF_Review_Patch(); $patch->review = $review; $patch->summary = __('Initial patch to be reviewed.'); $patch->description = $this->cleaned_data['description']; $patch->commit = self::findCommit($this->cleaned_data['commit']); $patch->patch = $this->cleaned_data['patch']; $patch->create(); $patch->notify($this->project->getConf()); /** * [signal] * * IDF_Review::create * * [sender] * * IDF_Form_ReviewCreate * * [description] * * This signal allows an application to perform a set of tasks * just after the creation of a review and the notification. * * [parameters] * * array('review' => $review, * 'patch' => $patch); * */ $params = array('review' => $review, 'patch' => $patch); Pluf_Signal::send('IDF_Review::create', 'IDF_Form_ReviewCreate', $params); return $review; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // Add a tag for each label $tags = array(); for ($i = 1; $i < 7; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tag = IDF_Tag::add($name, $this->project, $class); $tags[] = $tag->id; } } // Create the upload $this->upload->summary = trim($this->cleaned_data['summary']); $this->upload->changelog = trim($this->cleaned_data['changelog']); $this->upload->modif_dtime = gmdate('Y-m-d H:i:s'); $this->upload->update(); $this->upload->batchAssoc('IDF_Tag', $tags); /** * [signal] * * IDF_Upload::update * * [sender] * * IDF_Form_UpdateUpload * * [description] * * This signal allows an application to perform a set of tasks * just after the update of an uploaded file. * * [parameters] * * array('upload' => $upload); * */ $params = array('upload' => $this->upload); Pluf_Signal::send('IDF_Upload::update', 'IDF_Form_UpdateUpload', $params); return $this->upload; }
/** * Convert the definition of tags in the configuration into the * corresponding list of tags. * * @param string Configuration key where the tag is. * @param string Default config if nothing in the db. * @param string Default class. * @return array List of tags */ public function getTagsFromConfig($cfg_key, $default, $dclass = 'Other') { $conf = $this->getConf(); $tags = array(); foreach (preg_split("/\r\n|\r|\n/", $conf->getVal($cfg_key, $default), -1, PREG_SPLIT_NO_EMPTY) as $s) { $_s = explode('=', $s, 2); $v = trim($_s[0]); $_v = explode(':', $v, 2); if (count($_v) > 1) { $class = trim($_v[0]); $name = trim($_v[1]); } else { $name = trim($_s[0]); $class = $dclass; } $tags[] = IDF_Tag::add($name, $this, $class); } return $tags; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } if ($this->show_full) { $tagids = array(); $tags = array(); for ($i = 1; $i < 4; $i++) { if (strlen($this->cleaned_data['label' . $i]) > 0) { if (strpos($this->cleaned_data['label' . $i], ':') !== false) { list($class, $name) = explode(':', $this->cleaned_data['label' . $i], 2); list($class, $name) = array(trim($class), trim($name)); } else { $class = 'Other'; $name = trim($this->cleaned_data['label' . $i]); } $tag = IDF_Tag::add($name, $this->project, $class); $tags[] = $tag; $tagids[] = $tag->id; } } // Compare between the old and the new data $changes = array(); $oldtags = $this->page->get_tags_list(); foreach ($tags as $tag) { if (!Pluf_Model_InArray($tag, $oldtags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = (string) $tag; //new tag } else { $changes['lb'][] = (string) $tag->name; } } } foreach ($oldtags as $tag) { if (!Pluf_Model_InArray($tag, $tags)) { if (!isset($changes['lb'])) { $changes['lb'] = array(); } if ($tag->class != 'Other') { $changes['lb'][] = '-' . (string) $tag; //new tag } else { $changes['lb'][] = '-' . (string) $tag->name; } } } if (trim($this->page->summary) != trim($this->cleaned_data['summary'])) { $changes['su'] = trim($this->cleaned_data['summary']); } // Update the page $this->page->batchAssoc('IDF_Tag', $tagids); $this->page->summary = trim($this->cleaned_data['summary']); $this->page->title = trim($this->cleaned_data['title']); } else { $changes = array(); } $this->page->update(); // add the new revision $rev = new IDF_WikiRevision(); $rev->wikipage = $this->page; $rev->content = $this->cleaned_data['content']; $rev->submitter = $this->user; $rev->summary = $this->cleaned_data['comment']; $rev->changes = $changes; $rev->create(); $rev->notify($this->project->getConf(), false); return $this->page; }