function mail_update_7_8() { $sent_mails = MailContents::findAll(array('conditions' => "`state`=3 AND `has_attachments`=1")); foreach ($sent_mails as $mail) { if (!$mail instanceof MailContent) { continue; } /* @var $mail MailContent */ $attachments = array(); MailUtilities::parseMail($mail->getContent(), $decoded, $parsedEmail, $warnings); if (isset($parsedEmail['Attachments'])) { $attachments = $parsedEmail['Attachments']; } else { if ($mail->getHasAttachments() && !in_array($parsedEmail['Type'], array('html', 'text', 'delivery-status')) && isset($parsedEmail['FileName'])) { // if the email is the attachment $attachments = array(array('Data' => $parsedEmail['Data'], 'Type' => $parsedEmail['Type'], 'FileName' => $parsedEmail['FileName'])); } } foreach ($attachments as $att) { $file = ProjectFiles::getByFilename($att['FileName']); /* @var $file ProjectFile */ if ($file instanceof ProjectFile) { $file->setMailId($mail->getId()); $file->setMarkTimestamps(false); // dont change updated_on date $file->save(); $file->addToSharingTable(); } } } DB::executeAll("UPDATE " . TABLE_PREFIX . "objects o INNER JOIN " . TABLE_PREFIX . "project_files f ON f.object_id=o.id\n\t\t\tSET o.updated_by_id=o.created_by_id, o.updated_on=o.created_on\n\t\t\tWHERE f.mail_id>0;"); }
/** * Function called from other controllers when creating a new object an linking objects to it * * @param void * @return null */ function link_to_new_object($the_object) { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $objects = array_var($_POST, 'linked_objects'); if (is_array($objects) && count($objects) > 0 && !$the_object->isNew() && !$the_object->canLinkObject(logged_user())) { flash_error(lang("user cannot link objects")); return; } $the_object->clearLinkedObjects(); if (is_array($objects)) { $err = 0; foreach ($objects as $objid) { $split = explode(":", $objid); if ($split[0] == $the_object->getId()) { continue; } if (count($split) == 1) { $object = Objects::findObject($split[0]); } else { if (count($split) == 3 && $split[2] == 'isName') { $object = ProjectFiles::getByFilename($split[1]); } else { continue; } } if ($object->canLinkObject(logged_user())) { $the_object->linkObject($object); if ($the_object instanceof ContentDataObject) { ApplicationLogs::createLog($the_object, ApplicationLogs::ACTION_LINK, false, null, true, $object->getId()); } if ($object instanceof ContentDataObject) { ApplicationLogs::createLog($object, ApplicationLogs::ACTION_LINK, false, null, true, $the_object->getId()); } } else { $err++; } } if ($err > 0) { flash_error(lang('some objects could not be linked', $err)); } } }
function filenameExists($filename){ $file = ProjectFiles::getByFilename($filename); return $file instanceof ProjectFile; }
function fileExists($username, $password, $filename) { $result = array('status' => true, 'errorid' => 0, 'message' => ''); if ($this->loginUser($username, $password)) { $file = ProjectFiles::getByFilename($filename); $result['status'] = $file != null; if ($file != null) { $this->initXml('result'); $this->instance->startElement('status'); $this->instance->text('true'); $this->instance->endElement(); $this->instance->startElement('errorid'); $this->instance->text(0); $this->instance->endElement(); $this->instance->startElement('message'); $this->file_toxml($file); $this->instance->endElement(); $xml = $this->endXml(); } else { $result['errorid'] = 1001; $result['message'] = lang('file dnx'); $xml = $this->result_to_xml($result, 'result'); } } else { $result['status'] = false; $result['errorid'] = 1002; $result['message'] = lang('invalid login data'); $xml = $this->result_to_xml($result, 'result'); } return $xml; }