Esempio n. 1
0
 public function Fire()
 {
     if ($this->input->do == 'submit') {
         $bug = new Bug($this->input->bug_id);
         try {
             $bug->FetchInto();
         } catch (phalanx\data\ModelException $e) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND')));
             return;
         }
         $body = trim($this->input->body);
         if (empty($body)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY')));
             return;
         }
         $comment = new Comment();
         $comment->bug_id = $bug_id;
         $comment->post_user_id = Bugdar::$auth->current_user();
         $comment->post_date = time();
         $comment->body = $body;
         $comment->Insert();
         $this->comment_id = $comment->comment_id;
         $search = new SearchEngine();
         $search->IndexBug($bug);
         EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $bug_id, l10n::S('USER_REGISTER_SUCCESS')));
     }
 }
Esempio n. 2
0
 public function Fire()
 {
     $do_insert = $this->input->action == 'insert';
     $do_update = $this->input->action == 'update';
     if ($this->input->_method != 'POST') {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent('Request must be POSTed'));
         return;
     }
     // Create an empty Model object if creating a new bug, or fetch the data of
     // an existing bug to update.
     if ($do_insert) {
         $bug = new Bug();
     } else {
         if ($do_update) {
             $bug = new Bug($this->input->bug_id);
             try {
                 $bug->FetchInto();
             } catch (\phalanx\data\ModelException $e) {
                 EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND')));
                 return;
             }
         } else {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent('Invalid bug operation'));
             return;
         }
     }
     $this->action = $this->input->action;
     $user = Bugdar::$auth->current_user();
     $title = trim($this->input->title);
     if (empty($title) && $do_insert) {
         EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_MISSING_TITLE')));
         return;
     }
     Bugdar::$db->BeginTransaction();
     $now = time();
     if (!empty($title)) {
         $bug->title = $title;
     }
     if ($do_insert) {
         $bug->reporting_user_id = $user->user_id;
         $bug->reporting_date = $now;
         $bug->Insert();
     } else {
         if ($do_update) {
             $bug->Update();
         }
     }
     // Now set the bug_id output value, which will be set after a call to
     // Insert().  Updated bugs will have this set from FetchInto().
     $this->bug_id = $bug->bug_id;
     // Add a comment if one is present.
     $body = trim($this->input->comment_body);
     if (!empty($body) || $do_insert) {
         if ($do_insert && empty($body)) {
             EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY')));
             return;
         }
         $comment = new Comment();
         $comment->bug_id = $this->bug_id;
         $comment->post_user_id = $user->user_id;
         $comment->post_date = $now;
         $comment->body = $body;
         $comment->Insert();
         $this->comment_id = $comment->comment_id;
         // Update the bug so it can find that first comment easiliy.
         if ($do_insert) {
             $bug = new Bug($bug->bug_id);
             $bug->first_comment_id = $comment->comment_id;
             $bug->Update();
             $bug->FetchInto();
         }
     }
     // Handle tags.
     if (is_array($this->input->tags_new)) {
         foreach ($this->input->tags_new as $tag) {
             $bug->SetAttribute('', $tag);
         }
     }
     if (is_array($this->input->tags_deleted)) {
         foreach ($this->input->tags_deleted as $tag) {
             $bug->RemoveAttribute($tag, TRUE);
         }
     }
     // Create a map of all the set attributes.
     $set_attributes = array();
     if (is_array($this->input->attributes)) {
         foreach ($this->input->attributes as $attr) {
             // If this is an empty attribute, ignore it.
             if (empty($attr['title']) || empty($attr['value'])) {
                 continue;
             }
             $set_attributes[$attr['title']] = $attr['value'];
         }
         // Get all potential attributes; this includes defined tags.
         $attributes = Attribute::FetchGroup();
         foreach ($attributes as $attr) {
             // If the user is allowed to write to this attribute, update the
             // value.
             if ($attr->is_attribute() && $attr->CheckAccess($user, $bug) & Attribute::ACCESS_WRITE) {
                 // If there is no value for this attribute, then it was removed.
                 if (!isset($set_attributes[$attr->title])) {
                     $bug->RemoveAttribute($attr->title, $attr->is_tag());
                     continue;
                 }
                 // Otherwise, update the value.
                 $validate = $attr->Validate($set_attributes[$attr->title]);
                 if ($validate[0]) {
                     $bug->SetAttribute($attr->title, $validate[1]);
                     unset($set_attributes[$attr->title]);
                 }
             }
         }
         // Any remaining set_attributes are not formally defined.  If the user
         // has permission to set ad-hoc attributes, do so.
         if (TRUE) {
             // TODO: check permission
             foreach ($set_attributes as $title => $value) {
                 $bug->SetAttribute($title, $value);
             }
         }
     }
     Bugdar::$db->Commit();
     $search = new SearchEngine();
     $search->IndexBug($bug);
     $string = $do_insert ? l10n::S('BUG_CREATED_SUCCESSFULLY') : l10n::S('BUG_EDIT_SUCCESS');
     EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $this->bug_id, $string));
 }
Esempio n. 3
0
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program.  If not, see <http://www.gnu.org/licenses/>.
// This script will re-index the search system. It is meant to be run at
// the TOP LEVEL of Bugdar's directory.
define('BUGDAR_ROOT', getcwd());
define('PHALANX_ROOT', BUGDAR_ROOT . '/phalanx');
require_once BUGDAR_ROOT . '/includes/core.php';
require_once BUGDAR_ROOT . '/includes/search_engine.php';
// Load the database.
$config = new phalanx\base\KeyDescender(require BUGDAR_ROOT . '/includes/config.php');
Bugdar::BootstrapDatabase($config);
// This is going to take a while...
set_time_limit(0);
ini_set('max_execution_time', 0);
// Destroy the old index and create a new one.
echo 'Destroying old index for ' . BUGDAR_ROOT . "\n";
exec('rm -rf ' . BUGDAR_ROOT . '/cache/lucene_index');
clearstatcache();
echo 'New index created' . "\n";
$search = new SearchEngine();
$bugs = Bugdar::$db->Query("SELECT * FROM " . TABLE_PREFIX . "bugs");
while ($bug = $bugs->FetchObject()) {
    $search->IndexBug($bug);
    echo ".";
}
echo "\nDone!\n";